You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When following the example https://github.com/zapier/zapier-platform/blob/main/example-apps/files/creates/uploadFile_v10.js the file that is uploaded does not retain its original name. Instead we get a seemingly random sequence of characters as the name.
I can see that the example expects the consumer to specify the name as a separate field, but it would be good to not require the user to do this.
Reproduction Steps
Create an app which uploads a file from a single field as the above example
Send a file to that app with a meaningful name
Zapier Platform version
CLI version: 15.12.0
Node.js version: v20.10.0
OS info: darwin-arm64
zapier-platform-core dependency: 15.12.0
Node.js version
v20.10.0
Your Operating System
macOS 14.5
npm/yarn version
4.4.0
App ID
147940
More Details
No response
The text was updated successfully, but these errors were encountered:
I've found a solution to this issue, turns out the endpoint generated by Zapier to download the file keeps the filename in the Content-Disposition header. It is therefore possible to access it when we download the file in preparation for the upload.
consthttp=require('https');constFormData=require('form-data');functiongetFileName(disposition){constutf8FilenameRegex=/filename\*=UTF-8''([\w%\-\.]+)(?:;?|$)/i;constasciiFilenameRegex=/^filename=(["']?)(.*?[^\\])\1(?:;?|$)/i;letfileName='attachment.bin';if(utf8FilenameRegex.test(disposition)){fileName=decodeURIComponent(utf8FilenameRegex.exec(disposition)[1]);}else{// prevent ReDos attacks by anchoring the ascii regex to string start and// slicing off everything before 'filename='constfilenameStart=disposition.toLowerCase().indexOf('filename=');if(filenameStart>=0){constpartialDisposition=disposition.slice(filenameStart);constmatches=asciiFilenameRegex.exec(partialDisposition);if(matches!=null&&matches[2]){fileName=matches[2];}}}returnfileName;}functionmakeDownloadStream(url){returnnewPromise((resolve,reject)=>{http.request(url,(res)=>{// We can risk missing the first n bytes if we don't pause!res.pause();constfilename=getFileName(res.headers['content-disposition']);resolve({stream: res, filename });}).on('error',reject).end();});}// NOTE: The above function now returns an object with both the stream and filename instead of just the stream// Change downstream code accordingly// ie.// ...form.append('file',stream.stream,stream.filename);// All set! Resume the streamstream.stream.resume();
Bug Description
When following the example https://github.com/zapier/zapier-platform/blob/main/example-apps/files/creates/uploadFile_v10.js the file that is uploaded does not retain its original name. Instead we get a seemingly random sequence of characters as the name.
I can see that the example expects the consumer to specify the name as a separate field, but it would be good to not require the user to do this.
Reproduction Steps
Zapier Platform version
zapier-platform-core
dependency: 15.12.0Node.js version
v20.10.0
Your Operating System
macOS 14.5
npm/yarn version
4.4.0
App ID
147940
More Details
No response
The text was updated successfully, but these errors were encountered: