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 TheCwal · Aug 15, 2013 at 07:19 PM · wwwdownloadable content

Is it possible to pull the file name from a WWW get?

I am using a WWW request to pull a file from a remote server and subsequently save it to the user's device. The problem I have encountered is that I haven't been able to extract the name of the file that is downloaded, which is a function I was relying on to allow downloading differently named files.

Comment
Add comment · Show 2
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 Joyrider · Aug 15, 2013 at 07:43 PM 1
Share

I don't get it... if you download a file from a server... you should already know the name of the file, no? How else can you get it?

avatar image TheCwal · Aug 15, 2013 at 08:00 PM 0
Share

I'm working on the assumption that it is possible clients won't give me access at the level I would prefer. I am building the download client to take any sort of url, including those generated by sites like soundcloud, which format the end or the url as download?client_id=b45b1aa10f1ac2941910a7f0d10f8e28

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Aug 15, 2013 at 09:10 PM

Actually there is no "filename". You send a get request to a server for a specific resource (your URL) and the server returns that resource. It doesn't have to be a file. It could be some data from a database, so there's no filename. HTTP doesn't really support a way to give the resource a "name".

Most browsers however support reading an additional Content-Disposition header which is actually not part of HTTP. If the server adds such an header you might read the possible filename from there, but most servers don't include that header.

An HTTP response just consists of:

  • the status line

  • additional headers

  • (an empty line)

  • the data

There are only a few response headers and "Content-Disposition" is the only one that even mentions a filename. So in most cases you would either:

  • extract the filename from the Content-Disposition header if available

  • extract the filename fromt the request URL which is a bit tricky since you will have a hard time to decide what is a filename and what not.

  • generate your own random filename (like Unity does when dragging images from the browser into Unity).

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 jacobschellenberg · Aug 15, 2013 at 07:46 PM

It's actually just one more step after pulling the object. In this example, I'm asking for the name of the www.texture

 using UnityEngine;
     using System.Collections;
     
     public class Example : MonoBehaviour {
         public string url = "http://images.earthcam.comec_metrosourcams/fridays.jpg";
         IEnumerator Start() {
             WWW www = new WWW(url);
             yield return www;
             renderer.material.mainTexture = www.texture;
             Debug.Log("Texture Name: " + www.texture.name);
      }   
     }
Comment
Add comment · Show 1 · 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 TheCwal · Aug 15, 2013 at 08:12 PM 0
Share

I am downloading audio files, which are passed through .GetAudioClip(true, false, AudioType.$$anonymous$$PEG); which doesn't let me access the filename after the conversion. The debug log just returns an empty string. Unfortunately there doesn't seem to be a way to access a name field before the conversion.

Edit: The above code actually returns an empty string for the texture name.

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

18 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

Related Questions

Using Occlusion Culling with remotely downloaded Asset Package 0 Answers

Unity for showing a html stream 0 Answers

Downloaded bundle has bytes.Length == 0 0 Answers

StopAllCoroutines does NOT cancel a yield WWW download? 2 Answers

Why does nothing happen after yield return www 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