Added files not being recieved
See original GitHub issueExpected Behavior
Send file to specified URL for storage
Actual Behavior
RestRequest.Files.Add(…) states the file has been added, but when RestClient.Execute(RestRquest) goes, I get a response “No files received”. This worked on the previous version. No code has changed from either my platform or the WebAPI it’s communicating with. What has changed that might be causing this?
Steps to Reproduce the Problem
`private bool uploadPDF(SpoolDataRow pRow)
{
RestClient pClient = new RestClient(m_pLoginMgr.Server);
pClient.Authenticator = new HttpBasicAuthenticator(m_pLoginMgr.Username, m_pLoginMgr.Password);
RestRequest pPDFRequest = new RestRequest(Config.API_PUT_SPOOL_PDF(pRow.ID), Method.POST);
pPDFRequest.AddHeader("Content-Type", "application/x-www-form-urlencoded");
byte[] arBytes = File.ReadAllBytes(pRow.PDF);
if (arBytes == null) return false;
pPDFRequest.Files.Add(new FileParameter()
{
Name = "SpoolFile",
Writer = pWriter =>
{
using (StreamReader pFile = new StreamReader(new MemoryStream(arBytes)))
{
pFile.BaseStream.CopyTo(pWriter);
}
},
FileName = Path.GetFileName(pRow.PDF),
ContentLength = arBytes.Length,
ContentType = "application/octet-stream"
});
IRestResponse pResponse = pClient.Execute(pPDFRequest);
return pResponse.StatusCode == System.Net.HttpStatusCode.OK;
}
`
Specifications
- Version: 106.2.1
- Platform: Windows 10, Autodesk Revit
- Subsystem:
StackTrace
Issue Analytics
- State:
- Created 6 years ago
- Comments:23 (9 by maintainers)
Top Results From Across the Web
Cannot see new files added to my git working directory
Git did not show any new files added to my project. Mine was caused by the following: Somehow my project's main folder got...
Read more >Fix problems uploading files on the OneDrive website
You don't have permission to upload the file to the folder that you selected. Select a folder that you have permission to edit,...
Read more >I'm having trouble with a shared folder
There are a few situations when your shared folders might not work as expected. Learn how to fix problems with shared folders.
Read more >2.2 Git Basics - Recording Changes to the Repository
Setting up a .gitignore file for your new repository before you get going is generally a good idea so you don't accidentally commit...
Read more >Add, edit, and commit to source files | Bitbucket Cloud
Create your new files or edit existing files in your local project directory. ... Enter git status to see the changes to be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I attempted to debug this but didn’t come up with anything. I’m also running into the same issue. On the receiving end the HttpContext.Current.Request.Files.Count is 0 (zero) even though I see (when debugging in the RestSharp code) that the stream is being written. I’m going to revert to the previous version (105.2.3), which works fine when posting a file to our api.
I know this is closed, but for those who may still be encountering this problem, here’s what I found and how we fixed it.
@bryanparke and I have been trying to upgrade to newer versions of RestSharp for a while now, and kept hitting this error on file uploads, which forced us to rollback to version 106.1.0 each time. Ultimately, we tracked this down to a call to
request.AddHeader("Content-Type", "application/json");
Once we removed the call to add that header, files started coming through in the controller just fine.In our case we were usually expecting to be sending json content so we had always been attaching the Content-Type header whether sending json or uploading files, which had been working. But versions newer than 106.1.0 were no longer sending the files while adding the “Content-Type” header.
Hopefully this can help someone…