filepond
filepond copied to clipboard
[Feature] Differentiate between chunked and regular uploads when fetching headers for process endpoint
Is there an existing issue for this?
- [x] I have searched the existing issues
Is your feature request related to a problem? Please describe.
I'm the author of https://github.com/sopamo/laravel-filepond and am currently working on a feature that allows users to use Azure's special "append only" blob type. For this, I need to know the content-type of the file when initialising the blob. I initialize the blob when /process is called on the server. Each PATCH call with the chunk data then just appends the chunk data to the append only blob. I can set the content type in the headers function like this:
{
url: api.getURL("/filepond/api"),
process: {
url: "/process",
headers: (file: File) => {
return { ...defaultHeaders, "Upload-Name": file.name, "Content-Type": file.type }
},
withCredentials: true,
},
patch: {
url: "/?patch=",
headers: defaultHeaders,
withCredentials: true,
},
revert: {
url: "/process",
headers: defaultHeaders,
withCredentials: true,
},
}
This works perfectly when uploading chunks.
The issue is, that when not uploading chunks (e.g. when the file is smaller than chunkSize, this doesn't work, because it will override the Content-Type of the request that uploads the full file, which is an issue, because for regular multipart uploads the content type needs to be multipart/form-data; boundary=----WebKitFormBoundary...
I could not find a way to differentiate between chunked uploading and non-chunked uploading in the headers function.
Describe the solution you'd like
One solution would be to add the type of upload to the metadata that is passed as a second parameter to the headers function? Or passing in a third parameter with the upload type to the headers function.
Are there any other obvious solutions I'm missing that might not even require a code change in filepond? I'd be open to creating a PR with a solution if you have a preferred way of implementing it - even knowing that v5 is right around the corner (maybe, hopefully :) )
Describe alternatives you've considered
A workaround is currently to force chunking, but that's not ideal of course.
Hey Paul!
I'm not sure I fully understand, but I wonder if checking if the file size is below the chunkSize in the headers function would be a way to test if FilePond is uploading chunks?