Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentLength missing in FileParameter #814

Closed
glecchi opened this issue Feb 11, 2016 · 5 comments
Closed

ContentLength missing in FileParameter #814

glecchi opened this issue Feb 11, 2016 · 5 comments

Comments

@glecchi
Copy link

glecchi commented Feb 11, 2016

The AddFile method with Writer Delegate param on RestRequest doesn't set the file ContentLength.
When Delegate write on Request stream throw a ProtocollViolationException (The number of bytes to be written to the stream exceeded Content-Length size specified) because file ContentLength is zero.

@kfstorm
Copy link

kfstorm commented May 9, 2016

I met the same issue. Any one have update?

@glecchi
Copy link
Author

glecchi commented May 11, 2016

No one.. for the moment the only workaround i found is to set the ContentLength manually on the Request.

@alexeyzimarev
Copy link
Member

I guess since the method now requires to specify the length, this issue can be closed

public IRestRequest AddFile(string name, Action<Stream> writer, string fileName, long contentLength,  string contentType = null)

@alexeyzimarev
Copy link
Member

No, I am wrong, actually, you meant using AddFile(FileParameter p)

@alexeyzimarev alexeyzimarev reopened this Jan 20, 2019
@alexeyzimarev
Copy link
Member

Ok, here is the thing. We give you an option to write directly to the request stream. How would you expect us to know the length of the data that you will be writing to it? There is a FileParameter.ContentLength property that you need to set and everything will work. The thing is that in reality, we must set the content length before writing to the request stream, especially valid for async calls. So, please, if it is a file, read the file size and set the file parameter length. I would even make the AddFile(FileParameter) method private, it seems to be misused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants