Comments (5)
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 MultipartParser
and MultipartSerializer
as part of the Vapor
module.
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.
from multipart-kit.
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
When running through Xcode, set the environment variable FILE_PATH
to your own file path (the file is included in the project as well)
from multipart-kit.
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 MultipartKit
the data is almost 2x the data I get from using my small helper.
So I tried to replicate as much as possible what MultipartKit is doing
- I created my
multipartData
using my small helper
let multipartData = try MultipartHelper().multipart(
from: fileUrl.path,
partName: "file",
boundary: boundary
)
- I created a new ByteBuffer and I wrote the data there
var buffer = ByteBufferAllocator().buffer(capacity: 0)
buffer.writeBytes(multipartData)
- I converted the buffer to a
String
let bufferString = String(decoding: buffer.readableBytesView, as: UTF8.self)
- I expected to have
multipartData.count
equal toData(bufferString.utf8).count
print(Data(bufferString.utf8).count == multipartData.count) // got `false`
When I compare the string result of this operation (bufferString
) to the string I get directly using MultipartSerializer
, they are identical
let body = try MultipartSerializer().serialize(
parts: [multipart],
boundary: boundary
)
print(body == bufferString) // got `true`
from multipart-kit.
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 String
internally so it can corrupt input data.
You have to use the latter.
from multipart-kit.
@dalu93 are you seeing this in the latest release? We've rewritten the parser in Swift so hopefully this issue has been resolved
from multipart-kit.
Related Issues (20)
- Replace [File] encoding with a real, generic solution HOT 1
- streaming support HOT 4
- Data or File Data Member of Decodable Parsed Incorrectly on Linux HOT 3
- Add null-termination to strncpy call HOT 2
- Parsing error
- Crash on multipart/form-data decoding with empty mime type. HOT 2
- Explore optimizing parser
- Bug in FormDataEncoder with Optional<CustomValue> HOT 3
- Decoding String enum
- Unable to decode nested `multipart` array.
- Decoding optional type cause error HOT 1
- Unnecessary conversions between `[UInt8]` and `ByteBuffer` HOT 2
- Is there any reason multipart-kit requires macOS 10.15? HOT 2
- Allow alternative parsing strategies in addition to the current "indexed brackets" convention
- Add support for decoding multipart/form-data without knowing the boundary
- Un-vendor the `swift-collections` implementation HOT 5
- Performance issue HOT 3
- How to upload file on iOS? HOT 11
- Encoding corrupts data
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from multipart-kit.