Hi, CC'ing the Pharo Users ML since that gives a permanent record of my answer.
File uploads using ZnClient do work in the common case. You can check ZnServerTest>>#testFormTest3 or ZnImageExampleDelegateTest>>#testUpload as well as several other senders of #addPart: First you are mixing 2 types of forms (see https://ci.inria.fr/pharo-contribution/job/EnterprisePharoBook/lastSuccessfulBuild/artifact/book-result/Zinc-HTTP-Client/Zinc-HTTP-Client.html section 6. Submitting HTML Forms). For a file upload you need a ZnMultiPartFormDataEntity which is configured automatically in ZnClient by #multiPartFormDataEntity when you do #addPart: (no need to set a content type). Next you are mixing the file name and the file contents. It is best to use the class side ZnMimePart instance creation methods, either #fieldName:fileName:entity: or #fieldName:fileNamed: Also, when you create a ZnByteArray entity with the contents of a .jpg or .png you not only have to load the actual bytes (obviously), but you also have to set the mime type correctly. In #fieldName:fileNamed: you can see how this is done by using the file extension, but that is just one way to do it, if you know the type upfront, just set it. There is also ZnClient>>#uploadEntityFrom: (used by #testUploadSmallDocument) but that is not using a form. I am sure you will be able to figure it out, if not just ask. Sven > On 30 Aug 2020, at 09:51, Sabine Manaa <manaa.sab...@gmail.com> wrote: > > Hi Sven, > > I hope you are well this serious times! > > I have a problem with ZnClient. I was asking yesterday in Discord but > we did not find a solution. > > https://discordapp.com/channels/223421264751099906/223421264751099906/749313351859044382 > > I write a summary here: > > I have this command, which works fine on the command line: > > curl -X POST > "https://my.sevdesk.de/api/v1/Voucher/Factory/uploadTempFile?token=32695d076245b124b0faaa56afc71b74" > -H "accept: application/xml" -H "Content-Type: multipart/form-data" -F > "file=@/Users/sabine/Desktop/belege/neue_belege/mcdonalds.jpeg;type=image/jpeg" > > Now, I want to "translate" this in a ZnClient command, but I do not > get it. my command is: > > ^ ZnClient new > systemPolicy; > https; > accept: ZnMimeType applicationXml; > headerAt: 'Content-Type' add: 'multipart/form-data'; > host: 'my.sevdesk.de'; > path: > '/api/v1/Voucher/Factory/uploadTempFile?token=32695d076245b124b0faaa56afc71b74'; > ifFail: [ :exception | exception response entity inspect ]; > formAt: 'file' put: > '@/Users/sabine/Desktop/belege/neue_belege/mcdonalds.jpeg'; > formAt: 'type' put: 'image/jpeg'; > post > > There must be a difference between the command line and the ZnClient > command because with the ZnClient command, I get this error: > {"objects":null,"error":{"message":"Uploaded file is not inside the > allowed directory","code":null,"data":null}}. > > I was also trying to get the command line from the ZnClient instance > with the method curl but that gives me this: > > echo > 66696c653d402f55736572732f736162696e652f4465736b746f702f62656c6567652f6e6575655f62656c6567652f6d63646f6e616c64732e6a70656726747970653d696d6167652f6a706567 > | xxd -r -p | curl -X POST > https://my.sevdesk.de:443/api/v1/Voucher/Factory/uploadTempFile?token=32695d076245b124b0faaa56afc71b74 > -H"User-Agent:Zinc HTTP Components 1.0 (Pharo/7.0)" > -H"Accept:application/xml" > -H"Content-Type:application/x-www-form-urlencoded" > -H"Host:my.sevdesk.de" -H"Content-Length:77" --data-binary @- > > Would be very nice if you could help me. All I want ist to "translate" > the above curl command in a corresponding ZnClient command.... > > Regards > Sabine