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
Short backstory, I pushed a new version of my backend a few days ago after testing it on my Mac extensively first, including file/photo upload. After pushing it and making sure things were still working, I discovered that file upload was broken everywhere. I boiled the issue down to an update in multipart to 3.0.4 from 3.0.3 that was the cause of the issue.
This issue at least exists on Linux running Swift 4.2 and later.
Pictures and files were being uploaded but the files saved were not what was uploaded. The files being saved included part of the actual file data but also included the parts of the multipart requests including the boundaries. The file/picture data portion is always cut off and never complete.
For example, I have a request that includes an integer and then a file for the other part. The file from the request once it has been decoded would look like:
I'll also include a file that is exactly what is saved when decoded from multipart 3.0.4 that was running on my server. If you open the file, you can see that the image portion of the request is cut off and incomplete.
Here's the struct I was using:
struct BackflowPayload: Decodable {
var image: File
var id: Int
}
I also tried this struct to see if there was a difference:
struct BackflowPayload: Decodable {
var image: Data
var id: Int
}
I did do some testing to see if I could find the exact cause. The image size in bytes is reported correctly on Linux when compared against the backend running on my Mac. I think the data start offset that is copied into the respective data member is incorrect for parts of type Data or File on Linux. My guess is that the number of bytes taken up by the other parts of the multipart requests is why the data/file portion being saved is cut off.
Short backstory, I pushed a new version of my backend a few days ago after testing it on my Mac extensively first, including file/photo upload. After pushing it and making sure things were still working, I discovered that file upload was broken everywhere. I boiled the issue down to an update in multipart to 3.0.4 from 3.0.3 that was the cause of the issue.
This issue at least exists on Linux running Swift 4.2 and later.
Pictures and files were being uploaded but the files saved were not what was uploaded. The files being saved included part of the actual file data but also included the parts of the multipart requests including the boundaries. The file/picture data portion is always cut off and never complete.
For example, I have a request that includes an integer and then a file for the other part. The file from the request once it has been decoded would look like:
I'll also include a file that is exactly what is saved when decoded from multipart 3.0.4 that was running on my server. If you open the file, you can see that the image portion of the request is cut off and incomplete.
Here's the struct I was using:
I also tried this struct to see if there was a difference:
I did do some testing to see if I could find the exact cause. The image size in bytes is reported correctly on Linux when compared against the backend running on my Mac. I think the data start offset that is copied into the respective data member is incorrect for parts of type Data or File on Linux. My guess is that the number of bytes taken up by the other parts of the multipart requests is why the data/file portion being saved is cut off.
test.txt
The text was updated successfully, but these errors were encountered: