Score:0

Unable to upload files through RESTful services

us flag

I am trying to upload pdf files to webform submission using REST API.

Since the Core File Upload functionality did not seem applicable for webform submission, I applied the patch from webform_rest module which would allow uploading files for webform submissions.

When POSTing the file via /webform_rest/{webform_id}/upload/{field_name} with the necessary Content-Type and Content-Disposition, Cookie and X-CSRF-Token per documentation, the file entity response's filesize value is always zero and correspondingly the destination file is empty. The file size and extension are in accordance to the settings in webform's Document file field. The public, private and tmp directories are writable and file upload works fine when performed through the webform submission form.

I tried to check if this issue is specific to the webform_rest resource by trying the File upload resource (/file/upload/{entity_type_id}/{bundle}/{field_name}) for a specific entity type with the respective file field and observed the same result of file being empty. To try and understand where the issue might be I looked into both the Rest resource code and tried checking the symfony $request->files parameter which appears to be empty in both cases.

Since the file upload functionality works fine within the site and related php configurations like file_uploads, upload_max_filesize, post_max_size are already set I'm uncertain as to how to approach this problem further

Would request some clarity on how I could debug this further and get it to work.

Score:0
us flag

Tried to check if the API behaved differently when hit through cURL instead of the Postman app which I had been relying on and it worked immediately. Realized it was an issue with either my workplace network preventing the file upload through postman or problem within the version of postman installed in my work computer.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.