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

How to correctly include PNG into formData? #49

Closed
dbambulaks opened this issue Jan 20, 2019 · 9 comments
Closed

How to correctly include PNG into formData? #49

dbambulaks opened this issue Jan 20, 2019 · 9 comments

Comments

@dbambulaks
Copy link

RestClient.Post(new RequestHelper {
    Uri = api + "/Documents/1/file",
    FormSections = new List<IMultipartFormSection>() { 
        new MultipartFormFileSection(File.ReadAllBytes(Application.streamingAssetsPath + "/test.png"))
    }
}).Then(r => {
    Debug.Log("uploaded");
}).Catch(err => Debug.Log(err.Message));

Doesn't work for me...

@jdnichollsc
Copy link
Member

Share logs please to see the error...

@jdnichollsc
Copy link
Member

jdnichollsc commented Jan 21, 2019

We're using this solution http://answers.unity.com/answers/1436091/view.html
Let me know if you have a better solution for that issue of Unity

@dbambulaks
Copy link
Author

UnityEngine.Debug:Log(Object)
<>c:<TestUpload>b__12_1(Exception) (at Assets/Inextia/Scripts/Inextia.cs:161)
RSG.<>c__DisplayClass44_0:<Catch>b__1(Exception)
RSG.Promise:InvokeRejectHandler(Action`1, IRejectable, Exception)
RSG.<>c__DisplayClass34_0:<InvokeRejectHandlers>b__0(RejectHandler)
RSG.Promises.EnumerableExt:Each(IEnumerable`1, Action`1)
RSG.Promise:InvokeRejectHandlers(Exception)
RSG.Promise:Reject(Exception)
RSG.<>c__DisplayClass44_0:<Then>b__1(Exception)
RSG.Promise`1:InvokeHandler(Action`1, IRejectable, Exception)
RSG.<>c__DisplayClass24_0:<InvokeRejectHandlers>b__0(RejectHandler)
RSG.Promises.EnumerableExt:Each(IEnumerable`1, Action`1)
RSG.Promise`1:InvokeRejectHandlers(Exception)
RSG.Promise`1:Reject(Exception)
Proyecto26.RestClient:Promisify(Promise`1, RequestException, ResponseHelper)
Proyecto26.<CreateRequestAndRetry>d__0:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

@jdnichollsc
Copy link
Member

Unity is so descriptive... Honestly, I have no idea. Can you try with the source code of the plugin and debug your code please?
Let me know, thanks in advance!

@dbambulaks
Copy link
Author

Maybe you can provide your example from forum? Can't make it work either with WWWForm() or boundary...

@jdnichollsc
Copy link
Member

Reviewing your logs, it looks like an unhandled exception, can you see other error using try/catch?

@dbambulaks
Copy link
Author

Nothing in try/catch :(

@dbambulaks
Copy link
Author

Ended up with this solution... :) And thanks for support!

        WWWForm form = new WWWForm();
        form.AddBinaryData("file", File.ReadAllBytes(filepath), name, mime);
        UnityWebRequest request = UnityWebRequest.Post(api + "/Documents/" + doc + "/file", form);
        yield return request.SendWebRequest();
        print("request completed with code: " + request.responseCode);
        if(request.isNetworkError) {
            print("Error: " + request.error);
        } else {
            print("Request Response: " + request.downloadHandler.text);
        }

@jdnichollsc
Copy link
Member

Ok, the new FormData property was included in the new version 2.5.0, check the README of the project.
Thanks for report this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants