0

I have a simple question.

I have a piece of code to upload a picture to my server. This code is developped in Javascript. It's a simple Javascript code which append File object (javascript) to my ajax request.

this.addPicture = function(file) {
var frm = new FormData();
frm.append("picture", file);
var xhr = new XMLHttpRequest();
xhr.open("POST", "/myserverurl", true);
xhr.send(frm);

It it possible to use File Object (Java) in this request ?

Thanks a lot

2
  • Are you asking about using a Java File object on the client side (in the browser) or on the server side (to handle the upload)? Commented Aug 12, 2013 at 9:55
  • My question is more in client side Commented Aug 12, 2013 at 9:56

2 Answers 2

1

No. Java and Javascript are completely different languages, and you can't use Java APIs in a Web page's Javascript. You might want to look at the HTML FileUpload form control for this purpose.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply. It is not possible also to create a File Object (Javascript Browser ) in Java and passed it to my API. In fact, my Java code called Javascript APi throw PhoneGap interface
0

Basically you wouldn't be able to use java inplace of javascript if that's the question.

You could sent the request as mentioned in your code above and then either handle it as a file object on the server side code in java

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.