2

I'm thinking of doing some online file manipulation for mobile users, the idea being that the user provides a URL to the file, then the file contents are modified by the JS, and can then be downloaded. But I haven't been able to figure out how to get the file when it's on a separate domain using just JS.

Is this possible? If so any hints or examples would be appreciated.

Just wanted to add that part of what I wanted to do was make it available without my hosting it. I'm thinking of something like a a file they can host somewhere,and then all of the bandwidth is their own...and that of wherever they are getting the file from of course.

jmoreno
  • 12,752
  • 4
  • 60
  • 91
  • [Same Origin Policy](https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript). – Jared Farrish Dec 12 '11 at 04:20
  • What is your target browser support and do you have access to the other domain's code? – alex Dec 12 '11 at 04:23
  • Main target is Safari under iOS, and no, no access to other domain. The file that I would be getting would always be some kind of binary, never a web page (but not necessarily of any particular mime type). – jmoreno Dec 12 '11 at 04:35

2 Answers2

2

The only way to load contents of a file on another domain is from within a <script> tag. This is how JSONP works. Look into getting your target file into this format.

The other way would be to use a local proxy. Create a web service method that loads and returns the contents of the file, then call that locally using your favorite JavaScript framework.

Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
1

Depending on how you think of public webservices, and within some limitations I'm still mapping, you can do this using an ajax call to YQL, like so.

(will expand the answer later).

http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20data.uri%20where%20url=%22http://t3.gstatic.com/images?q=tbn:ANd9GcSyART8OudfFJQ5oBplmhZ6HIIlougzPgwQ9qcgknK8_tivdW0EOg%22

One of the limitations of this method is file size, it currently tops out at 25k.

jmoreno
  • 12,752
  • 4
  • 60
  • 91