tags:

views:

31

answers:

1

Hi,

I've got a web project where my users signup at a url like:

www.mysite.com/signup/index.jsp

after the user signs up, I show them another page where they can submit a user photo if they want. But my user photos are going to be hosted at another domain I own - is it possible to post a form to another domain? Like the page they land at is here with the following form:

<!--
www.mysite.com/signup/photo.jsp
-->

<form method="POST" action="http://www.myothersite.com/photo.php" >
</form>

I'd ideally like to get the image the user selects to just go to my other domain, where I'll host it statically. Not sure if something like this is possible due to browser restrictions,

Thanks

+3  A: 

is it possible to post a form to another domain

Sure, no problem. There are no cross-domain restrictions, and no single origin policy, for HTML forms.

Unicron
Doesn't cross-site scripting blocks prevent this kind of stuff?
Jay
@Jay no. You are thinking of AJAX requests and iframes from other domains. There are zero restrictions on forms.
Unicron
You can post to another site, this is why CSRF can be done.
Leventix
Hmm although this could work, then I'll lose all session information when POST'ing to my other domain, right? Therefore my image upload service would be open, allowing anyone to submit photos for different users, I think?
@user yes, that would be a side effect. But if you need to associate uploads with users, why not accept the upload on server A and copy it across to server B internally?
Unicron
That could work - Server A is using java servlets, server B is using php - what should I search for to find out how to implement this? Not sure if this is a common technique
@user You could simulate a file upload to server B. I don't know Java but I'm 100% sure there's a library for it. Server B would take requests only from Server A's IP.
Unicron