Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 siddharth3322 · Jun 22, 2016 at 10:16 AM · serverwwwfileuploadwwwform

Failed to upload image over custom server

Using web service, I was trying to upload image to web server. At present I want to upload profile picture to custom server but in this always, I was getting this error in Unity editor.

alt text

For this, I was using following code:

 void Start ()
 {
     StartCoroutine (UploadPNG ());
 }
 
 IEnumerator UploadPNG ()
 {
     // We should only read the screen after all rendering is complete
     yield return new WaitForEndOfFrame ();
 
     // Create a texture the size of the screen, RGB24 format
     int width = Screen.width;
     int height = Screen.height;
     var tex = new Texture2D (width, height, TextureFormat.RGB24, false);
 
     // Read screen contents into the texture
     tex.ReadPixels (new Rect (0, 0, width, height), 0, 0);
     tex.Apply ();
 
     // Encode texture into PNG
     byte[] bytes = tex.EncodeToPNG ();
     Destroy (tex);
 
     // Create a Web Form
     WWWForm form = new WWWForm ();
     form.AddBinaryData ("profile_pic", bytes, "screenShot.png", "image/png");
 
     // Upload to a cgi script
     WWW w = new WWW (screenShotURL, form);
     yield return w;
     if (!string.IsNullOrEmpty (w.error)) {
         print (w.error);
     } else {
         print ("Finished Uploading Screenshot");
     }
 }
 


This is similar code that I found from here: WWWForm

As well screenshot after running url in PostMan.

alt text

Here is actual url to test:

 private string screenShotURL = "http://photo-competition.igts.co.in/restapi/image_upload_demo_ws";

Please suggest me at which place I have done mistake.

EDIT: Following two link give you source code used from PHP side.

Image Upload Part-1

Image Upload Part-2

screen-shot-2016-06-22-at-34345-pm.png (15.6 kB)
screen-shot-2016-06-22-at-45000-pm.png (113.7 kB)
Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by siddharth3322 · Jun 29, 2016 at 09:55 AM

Now I have answer for this question so that I am writing here. By considering that it may be useful to others.

Basically this problem is from server side. If I become specific towards problem then its IP address blockage problem. I transferred my web server source code from one server to other. Then after same above code worked perfectly and image gets uploaded without any problem.

So please before wasting any time, check your server side first because this kind of error definitely belong to server as per my understanding.

Comment
Add comment · Share
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
1

Answer by gorsefan · Jun 22, 2016 at 05:26 PM

It looks to me like a sub-optimally configured web server. If I hit the screenShotURL I get a 404 response, but I also get served XML;

 <?xml version="1.0" encoding="utf-8"?>
 <xml><status>0</status><error>Unknown method.</error></xml>

Hit another random page on that domain, you get a proper 404 response & page.

Now this is probably because I am trying to GET a URL which expects a POST along with other data, such as probably a hidden form field with a method name the web server expects. Responding with a 404 in this situation seems like poor HTTP to me as it looks like there is a resource there, it just doesn't like your request, or the web server is configured to serve different 404 responses from /restapi than the rest of the domain, which is weird. IMO it should respond with a 400 Bad Request, or 403 Forbidden, depending.

Short version, it looks to me like you are missing some data to fulfil the request & this isn't a Unity question. I'd look for a method parameter, check cookies, do you need to be signed in? etc etc. And read their restapi documentation. Either way, only the owner of that service can really help you I think...

Comment
Add comment · Show 4 · Share
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 siddharth3322 · Jun 22, 2016 at 08:03 PM 0
Share

Yes, you are right, by default i was using post method submission.

I think parameters and all other settings are correct, you can check this by postman screenshot that I have pasted.

Rest API documentation means?

avatar image gorsefan siddharth3322 · Jun 22, 2016 at 11:57 PM 0
Share

"I think parameters and all other settings are correct, you can check this by postman screenshot that I have pasted."

That is not possible because I dont know what the parameters are.

When you post to a web service, as you are doing, the types of data you post have to match the types of data expected by the PHP (or whatever) application running on the server. This matching of data types is what an API is. And a description of those data types is what I mean by "Rest API documentation" (REST can be understood as a type of web application architecture). No-one can know this apart from the person who wrote the PHP. You might be able to guess it from an HT$$anonymous$$L page that does what you are trying to do in Unity, but you need documentation of what the server code expects because it looks like you are not sending the correct data.

avatar image siddharth3322 gorsefan · Jun 23, 2016 at 09:19 AM 0
Share

@gorsefan, now i have added PHP source code link so that you can get more clear idea. Thanks for your suggestions.

Show more comments
avatar image
0

Answer by Abdis · Oct 09, 2018 at 04:53 PM

the php source code image seems doesn't longer exists, so if you don't mind, could you reupload the image or share your php code, i really need it @siddharth3322

Comment
Add comment · Show 2 · Share
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 siddharth3322 · Oct 09, 2018 at 05:11 PM 0
Share

this is a really old question so at present even I don't have those images as well ... I have deleted those

avatar image Abdis siddharth3322 · Oct 12, 2018 at 09:31 AM 0
Share

so, could i ask something, Unity send it as binary data, right? if Php side receive it, does it need to be converted again into file? or do i could handle it directly by using $_FILES["fileToUpload"]["tmp_name"] ? i have handle it directly like these, but it seems doesn't work

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

49 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

Related Questions

Upload large files 0 Answers

Blank web server response in multiple type data submission 1 Answer

Why isn't this $_POST working properly? 1 Answer

UnityWebRequest how to upload a file/gameobject 0 Answers

$_FILES is empty when I send a file from WWWForm 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