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 kamesenin · Aug 23, 2012 at 03:55 PM · androiduploadwwwform

Uploading file on Android

Hi! I am trying to upload file by WWWForm on my android device. Code worki in Unity3d editor and it uploads with no problem (I have ongui progress printed). When I run my app on my phone I select the file and my progress shows only '0%' then '100%' (like split secound). Offcourse file is not uploaded. I am using sample code:

 IEnumerator UploadFileCo(string localFileName, string uploadURL)
     {
         if(once==false){
         WWW localFile = new WWW("file:///" + localFileName);
         once=true;
             yield return localFile;
         
             
         if (localFile.error == null){
            Debug.Log("Loaded file successfully");
             
         }
         else
         {
             Debug.Log("Open file error: "+localFile.error);
             yield break; 
         }
 
         WWWForm postForm = new WWWForm();
 
        postForm.AddBinaryData("theFile",localFile.bytes,"localFileName","video/3gpp");
 
 
         upload = new WWW(uploadURL,postForm);
             
         yield return upload;
         if (upload.error == null){
             Debug.Log("upload done :" + upload.text);
         }
             else
             {
             Debug.Log("Error during upload: " + upload.error);
                 }
             }
     }

What I am doing wrong? Or is it my phone? I have manifest white permitions to access internet. My Android version 2.3.5. Also I am uploading .3gp file. Thanks for any advice.

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 BerggreenDK · Oct 24, 2012 at 08:16 PM 0
Share

I'm wondering if your path to the file is correct on the phone?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Oct 24, 2012 at 08:59 PM

Yep, like BerggreenDK said, have you pinned the problem down to the sending part? Are you sure the loading works? Just do some debugging. A quick and easy way to display debug information is to use a script like this:

 // MobileDebug.cs
 using UnityEngine;
 
 
 public class MobileDebug : MonoBehaviour
 {
     private Vector2 m_ScrollPos;
     private static string m_DebugText = "";
     public static void Log(string aText)
     {
         m_DebugText += aText + "\n";
     }
     void OnGUI()
     {
         GUILayout.BeginArea(new Rect(0,0,400,400));
         m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos);
         
         GUILayout.Label(m_DebugText);
         
         GUILayout.EndScrollView();
         GUILayout.EndArea();
     }
 }

Just attach this script to any GO in your scene (that isn't going to be destroyed) and instead of "Debug.Log();" or "print();" you use "MobileDebug.Log();".

Place some logs at meaningful places to see what happens. Make sure you also log the ".error" of the WWW object when it fails.

You might need to adjust the placement of the GUI.

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
0

Answer by kamesenin · Oct 25, 2012 at 10:32 AM

Thanks for answer but I am way pass that. My path to file was correct . I didn't pin point why it doesn't work, but came with other solution. Using FtpWebRequest:

 ftpRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftp+namex+".jpg"));
             ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
            // this.ftpRequest.Proxy = null;
             ftpRequest.UsePassive = true;
             ftpRequest.UseBinary = true;
             ftpRequest.Credentials = new NetworkCredential("xxx@xyz.com", "qwerty");
          
            
             FileInfo ff = new FileInfo(thumpath); 
             byte[] fileContents = new byte[ff.Length];
          
             
             using (FileStream fr = ff.OpenRead())
             {
                 fr.Read(fileContents, 0, Convert.ToInt32(ff.Length));
                 done=true;
             }
          
             using (Stream writer = ftpRequest.GetRequestStream())
             {
                 writer.Write(fileContents, 0, fileContents.Length);
             }

where "thumbpath" is my file path, "namex" is file name and "ftp" is ftp address. Login and password are pass in "NetworkCredential" . For me there were two disadvantages: 1. Not everyone have ftp , 2. When uploading, Unity app freezes but after upload everthing worked normal. Now I am using asset know as 'boxit' and it's perfect for my project. Hope that this post will help someone. Cheers!

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

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

9 People are following this question.

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

Related Questions

Is there a way to fix uploadprogress on mobile? 1 Answer

Help with saving XML files with PHP to a server 0 Answers

Upload Game For Beta 2 Answers

How to upload/download video from/to mobile 1 Answer

Upload large files 0 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