1

I have a Unity3d project from which I would like to upload & download files. I have the downloading (and other relevant Seafile API related calls) working as it should, but I can't seem to make uploading work correctly. I can also make the uploading part function using curl with a command such as

curl -H "Authorization: Token token-goes-here" -F file=@E:/sample.png -F filename=sample.png -F parent_dir=/ http://url.here/upload-api/1a95255d-ac0c-44d0-bfa5-dd2a46f2cc89

However, I have been unable to achieve the same type of call using WWW, or UnityWebRequest. Here is a sample of the code using WWW (I omitted the authorization token on purpose here, but adding it has no effect on the upload). I also constructed a similar call using UnityWebRequest, but I ran into same issue, where Seafile always returns a bad request -error.

    WWW localFile = new WWW("file:///" + "E:/sample.png");
    WWWForm requestData = new WWWForm();
    requestData.AddBinaryData("file", localFile.bytes);
    requestData.AddField("parent_dir", "/");
    requestData.AddField("filename", "sample.png");

    WWW req = new WWW(upload_url, requestData);
    yield return req;

When observing the packets sent by Unity3D and comparing them with packets sent using curl, I noticed a small difference, but I can't figure out what is the cause for it. The packet sent by curl is split into 4 parts, and the packet sent by Unity3D is split into 2 parts. I have tried to mess with the boundary, I have tried building the packet with UnityWebRequest as proposed in Unity3D forums, and I have also tried building the packet manually and using HttpWebRequest, but I always end up having the same issue where the curl -packet and the Unity3D -packet have a very slight difference, which somehow doesn't work with the Seafile. I have attached images of the difference in the packets sent by curl and from Unity.

Packet from Unity3D

Packet from curl

  • I notice on the curl version, the content type is application/octet-stream but the unity version is image/png. I wonder if something like `requestData.AddBinaryData("file", localFile.bytes, null, "application/octet-stream");` would help – Chris H Apr 24 '18 at 17:51

0 Answers0