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 Julian-Glenn · Jul 08, 2013 at 10:49 PM · iosuploadzipweb server

Upload a zip file to a web server iOS

Folks,

I've created a .zip archive of images, sounds and an SQL file. I need to upload it to a web server from which the user can later retrieve the .zip to install on another iOS device.

How would I go about this?

I know it will involve form.AddBinaryData, but just have no clue where to start.

I've seen many examples, but none that seem to exactly address my needs as most just deal with uploading .PNG.

Also: Is it necessary to have a .PHP file to receive the upload or can I just send it directly to a folder on the server?

Here is the code I've been using, but it always ends in a 405 error and no file is sent to the server. Do I need a php/asp page to receive the file?

 using UnityEngine;
 using System.Collections;
 
 public class UploadFile : MonoBehaviour {
     
 string mainUrl = "http://www.logomagik.com/upload/";
 string saveLocation;
     
     void Start() {
         saveLocation = GetDocumentPath.GetiPhoneDocumentsPath() + "/";
         StartCoroutine("PrepareFile");
     }
 
     IEnumerator PrepareFile() {
 
         Debug.Log("saveLoacation = " + saveLocation);
 
         //Read the zip file
 
         WWW loadTheZip = new WWW("file:///"+saveLocation+"myTestZip.zip");
 
         yield return loadTheZip;
 
         StepTwo (loadTheZip);
 
     }
 
     void StepTwo (WWW post) {
 
         StartCoroutine("UpoadTheZip",post);
 
     }
 
     IEnumerator UpoadTheZip (WWW post) {
 
         //Create a form to send, and add zip converted to byte array
 
         WWWForm form = new WWWForm();
 
         form.AddBinaryData("myTestZip",post.bytes,"myTestZip.zip","application/zip");
 
         //Send POST request
         string url = mainUrl;
 
         WWW POSTZIP = new WWW(url,form);
 
         Debug.Log("Sending zip...");
 
         yield return POSTZIP;
 
         Debug.Log("Zip sent!");
 
         Debug.Log("Obtained: "+POSTZIP.text);
 
     }
 }

ty, /Julian

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TinyDev · Jul 15, 2013 at 04:37 AM

To your specific question "Do I need a php/asp page to receive the file?" Yes, since you are using HTTP to send the file you will need to send to an HTTP server. A PHP/ASP page would be one way to receive the file - you need something in the request pipeline of the server to handle your request.

Edit: I've included some minimalistic code (below) an aspx page...copy paste and name file uploadFile.aspx (if your website is IIS...otherwise you could write something similar in PHP or a JSP or whatever). Using the ASPX page, change your url to http://{yourwebsite}/uploadFile.aspx (i.e. rather than http://{yourwebsite}/upload - that would work if you created a RESTful site with a template of /upload but that's a bit of work and a quick and dirty ASPX page will do the trick).
Your ZIP file will be retrieved from the POSTed request, and saved to a directory called {upload} off the root of your web root.
Change the directory as you see fit (I was just matching the URL you had).
The code below just sends a nominal response if successful and the exception message if not.
You will need to set the permissions on your web server to allow writing to whatever directory you specify. In IIS world that means giving the domain account for the app pool permission or specifically specifying ACLs for the directory. Depending on how the site is hosted that might be easy (e.g. GoDaddy using IIS and File Manager set permissions), on a hosted IIS site use IIS admin, and so on.

 <%@ Import Namespace="System"%>
     <%@ Import Namespace="System.IO"%>
     <%@ Import Namespace="System.Net"%>
     <%@ Import NameSpace="System.Web"%>
     
     <Script language="C#" runat=server>
         void Page_Load(object sender, EventArgs e)
         {
     
             foreach (string f in Request.Files.AllKeys)
             {
                 HttpPostedFile file = Request.Files[f];
                 string fqn = String.Format(Server.MapPath("\\upload\\{0}"), System.IO.Path.GetFileName(file.FileName));
                 try
                 {
                     file.SaveAs(fqn);
                     Response.Write("all good");
                 }
                 catch (Exception ex)
                 {
                     Response.Write(ex.ToString());
                 }
             }
         }
     </Script>
     <html>
     <body>
     </body>
     </html>
 
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

16 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

Related Questions

How to Upload a video from Android/iOS to a server without using WWW ? 3 Answers

Not able to Upload .ulf file in IOS license activation. 2 Answers

Very Large iOS Build Size Unity 5 3 Answers

Downloading file using web client not working in all servers 0 Answers

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


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