Jump to content

File Upload - Cross Doamin


johnnyg24

Recommended Posts

I have a form allowing the client to upload a photo. The catch is that I need this photo to be sent to a third party via AJAX. I know cross domain AJAX is either impossible or very tricky so I was looking to send the file to our server first and then over to the third partie's server (which returns some data in JSON) and then back to our server and back to the calling page. My thought was to send the image path to our ASP page, get the photo that way and then send the the photo to the third party however, I can't seem to be able to send the full path to our ASP page. So my questions are: 1) Can I send the full image path in a form? 2) Is this the best way to upload an image via AJAX cross domain? Thanks

Link to comment
Share on other sites

That's a little vague. From what I understand, a user uploads a photo. You need to somehow "send" that photo to another server (via FTP? email? POST request? Fedex? avian carrier?). You're trying to send the image path to your ASP page, where is that path coming from? Is that the path of the file on the client's computer? If so, you don't need that. If the client uploads the file to the ASP page then the ASP page already knows the path to the file on the server, wherever it was uploaded. In fact, it probably sets the path when it handles the upload. You may want to look into using a Flash movie for the upload, it isn't bound by the same restrictions as Javascript.

Link to comment
Share on other sites

Sorry about the vagueness, The client uploads the image using <input type=file> It needs to be send using a POST method to the third parties server. If my ASP page already knows what the file path is, then how do I access it? I don't think it's in the Request.Form variables.

Link to comment
Share on other sites

Unless you want to process the raw request stream yourself, with ASP you need to use a component to handle file uploads. It doesn't come with a clean built-in way to handle them. That is for the situation where they upload the file to your server first, and then you send it to the other server. Why not just have the form submit directly to the other server? Ajax doesn't handle file uploads, files are always submitted using a regular form even if an ajax library hides that fact.

Link to comment
Share on other sites

I could submit it directly to the other server however, the thirds party server only sends back a JSON string that I then need to do something with. If I submit it directly to them then the client gets redirected away from the calling page. I've tried using a jquery form plugin to avoid the redirection but there seems to be security issues. I keep getting this error in FF: Permission denied to access property 'document

Link to comment
Share on other sites

You should be using a hidden form in an iframe or something to do the submission, and get the response back. That isn't affected by Javascript restrictions, it's just a normal form submission even though it looks like ajax to the user. If you're using jQuery, look for support in jQuery for doing file uploads with ajax and what the options are. The permission issue may be caused by the src of the iframe changing to another domain.

Link to comment
Share on other sites

A while ago when I was working with ASP classic I used a component called aspSmartUpload to process the files, which would let me save the uploaded files somewhere on the server. There were several other components available then. I don't know how much support you're going to find now because ASP was superseded several years ago by ASP.NET, people just don't do much new development for ASP classic. The company that developed the upload component I used is no longer in business, for example. The reason why you need an upload component is because ASP doesn't process the incoming request stream automatically to handle that. You can access the request stream yourself, and parse it up and decode the parts to find the headers, form information, attachments like files, etc, but that's not very practical. Using an upload component like that also makes the usual Request.Form collection unavailable, all form data needs to be accessed through the upload component. That's just part of the fun of working with ASP classic.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...