Skip to content
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

posting a binary file fails, binary message not understood #66

Closed
jmari opened this issue Aug 3, 2021 · 1 comment
Closed

posting a binary file fails, binary message not understood #66

jmari opened this issue Aug 3, 2021 · 1 comment

Comments

@jmari
Copy link

jmari commented Aug 3, 2021

posting a binary file doing:

response := ZnClient new
ifFail:[ :ex | self dataLoadFailed: ex ];
headerAt:'x-api-key' put: self apiKey;
addPart: (ZnMimePart fieldName: #file fileNamed: aFileName );
url: self url, self apiUrlFileUpload;
post;
response.

Fails, giving message #binary not understood. Solved doing
....

mimeType isBinary ifTrue: [ fileStream := fileStream wrappedStream ].

....

fieldName: fieldName fileNamed: fileName
| mimeType size fileStream entity baseName |
mimeType := ZnMimeType forFilenameExtension: (ZnFileSystemUtils extensionFor: fileName).
fileStream := ZnFileSystemUtils oldFileStreamFor: fileName.
mimeType isBinary ifTrue: [ fileStream binary ].
size := ZnFileSystemUtils fileSizeFor: fileName.
(entity := ZnStreamingEntity type: mimeType length: size)
stream: fileStream.
baseName := ZnFileSystemUtils baseNameFor: fileName.
^ self fieldName: fieldName fileName: baseName entity: entity

@jmari
Copy link
Author

jmari commented Aug 23, 2021

Sorry it is an older versión

@jmari jmari closed this as completed Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant