Jump to content

File Upload - Cross Doamin


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 post
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 post
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 post
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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...