Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Solitown · Aug 28, 2020 at 09:28 PM · apiwebrequestwwwform

How to use UnityWebRequest to upload a File via Invision REST API

Hello There

I've been using UnityWebRequest to succesfully access some REST API endpoints. However when it comes to uploading files I couldn't get it to work and am wondering (this might be a bit of an open-ended question) what I am overlooking. I create a WWWForm like this, filling it with required parameters for the API request:

  WWWForm form = new WWWForm();
 form.AddField("category", 6);
 form.AddField("title", "testing.txt");
 form.AddField("description", "Just a file");
 form.AddBinaryData("files", data, "testing.txt", "text/plain");

data is the byte array of the file im trying to upload. I then do a UnityWebRequest.Post(url, form) and set the request headers. However I always end up getting a "NO_FILES" response from the server (No files were supplied). Here's the documentation of the API-Endpoint I'm trying to access (with a short description of the files parameter and error codes): https://invisioncommunity.com/developers/rest-api?endpoint=downloads/files/POSTindex

Instead of WWWForm, I've also tried using a List like this and received the same "NO_FILES" error from the server.

 List<IMultipartFormSection> formData = new List<IMultipartFormSection>();
         formData.Add(new MultipartFormDataSection("category", "6"));
         formData.Add(new MultipartFormDataSection("title", "testing.txt"));
         formData.Add(new MultipartFormDataSection("description", "Just a file"));
         formData.Add(new MultipartFormFileSection("files", data, "testing.txt", "text/plain"));

Thanks!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Getsumi3 · Aug 29, 2020 at 01:36 PM 0
Share

Hi. According to Invision REST API docs you also need to provide author id.

Everything else looks fine.

Here is an example that I'm using to upload files to server (not Invision REST API):

 IEnumerator UploadFileCo()
     {
         isProjectUploaded = false;
         yield return new WaitForEndOfFrame();
 
         var bytes = System.IO.File.ReadAllBytes(file_full_path);
 
         WWWForm form= new WWWForm();
         form.AddField("authToken", WebRequestHandler.i.token);
         form.AddField("modelId", objectID);
         form.AddField("projectType", "Templates");
         form.AddField("categoryId", categoryID);
         form.AddBinaryData("file", bytes, file_full_path, "application/zip");
 
         var uwr = UnityWebRequest.Post(api_upload, form);
 
         yield return uwr.SendWebRequest();
 
         if (uwr.isNetworkError || uwr.isHttpError)
             Debug.LogFormat("Error while uploading file. Stop upload process. \nError code: <color=red>{1}</color>", uwr.downloadHandler.text, uwr.error);
         else
         {
 
             // Debug.Log("upload project done: " + uwr.downloadHandler.text);
             isProjectUploaded = true;
 
         }
 
         uwr.Dispose();
 
     }



0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

134 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Image upload API works with postman but not working with Unity. -1 Answers

$_FILES is empty when I send a file from WWWForm 2 Answers

Unable to call external API (IBM Watson) via HTTP request? 1 Answer

Coroutine for WWW call not resuming 0 Answers

Can you post a json string as a body in Unity? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges