-
-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialization seems to contain wrong data #46
Comments
Hi @dalu93, unfortunately this library's 4.0.0 version is no longer being maintained. It was merged into vapor/vapor a while ago: https://github.com/vapor/vapor/tree/master/Sources/Vapor/Multipart. Eventually my goal is to split the package back out again and formally pitch this to the swift server work group's package index. Until then, you can access the That said, I'm not sure why the length is about 2x longer via MultipartKit here. Seeing the full output (attached as a .txt or something) could help. If this bug exists in the vapor/vapor version of this code I'm happy to fix it. |
Hi @tanner0101, Vapor is not an option for us since we are planning to create a very small CLI tool and importing the whole Vapor product is going to be heavy and useless. I created, however, an example repository where you can see the error: https://github.com/dalu93/multipartkit-issue |
Hi @tanner0101 have you had chance to have a look at it? Unfortunately I cannot run Vapor locally because I'm on MacOS Mojave (10.14) and Vapor only supports 10.15+. I was anyway able to verify few things: There is a difference in terms of bytes between the two methods, using
let multipartData = try MultipartHelper().multipart(
from: fileUrl.path,
partName: "file",
boundary: boundary
)
var buffer = ByteBufferAllocator().buffer(capacity: 0)
buffer.writeBytes(multipartData)
let bufferString = String(decoding: buffer.readableBytesView, as: UTF8.self)
print(Data(bufferString.utf8).count == multipartData.count) // got `false` When I compare the string result of this operation ( let body = try MultipartSerializer().serialize(
parts: [multipart],
boundary: boundary
)
print(body == bufferString) // got `true` |
There are two serialization methods: multipart-kit/Sources/MultipartKit/MultipartSerializer.swift Lines 10 to 14 in 73706f1
multipart-kit/Sources/MultipartKit/MultipartSerializer.swift Lines 26 to 45 in 73706f1
The former method you are using uses |
@dalu93 are you seeing this in the latest release? We've rewritten the parser in Swift so hopefully this issue has been resolved |
Hi,
I've been trying using this library (version 4.0.0-beta.2) together with AsyncHTTPClient to execute a multipart POST request, where I need to upload a file.
The expected request should look like the following
This request works well through Insomnia and I tried to convert it to Swift using MultipartKit as below
Unfortunately the data count (1130517) is quite bigger than expected (see Content-Length from Insomnia output).
I've tried my own implementation of this simple case using
Foundation
and I actually am able to create the correct payloadAnd
MultipartHelper.swift
Am I somehow using the library incorrectly?
The text was updated successfully, but these errors were encountered: