Skip to main content

I am trying to upload an image using AJAX where i. I have the local URL of my image and iI want to pass that image as a file to the web service to upload.

Suppose i have the local file URL as : file:///accounts/1000/shared/camera/IMG_00000322.jpg

Now using AJAX iI want to pass this to webservice, What will be the best way to do this,? I also i want show the progress. While while uploading

Using php in server side.

uploadImage : function(myImageUrl,chatId){

    var formData = new FormData();
    formData.append("chatId", chatId);
    formData.append("fileimage", myImageUrl);
    
        $.ajax(
        {
            type:"POST",
            url:"http://suresh.sp.in/butler/public/uploadimage/getimage",
            contentType:"image/png",
            dataType:"json",
            data:formData,
            success:function(uploaded){
                console.info(uploaded.status);
            },
            error:function(error){
                                    console.info(error);    
                                             
            }
        });
    
}

I am trying to upload an image using AJAX where i have the local URL of my image and i want to pass that image as a file to web service to upload.

Suppose i have the local file URL as : file:///accounts/1000/shared/camera/IMG_00000322.jpg

Now using AJAX i want to pass this to webservice, What will be the best way to do this, also i want show the progress. While uploading

Using php in server side.

uploadImage : function(myImageUrl,chatId){

    var formData = new FormData();
    formData.append("chatId", chatId);
    formData.append("fileimage", myImageUrl);
    
        $.ajax(
        {
            type:"POST",
            url:"http://suresh.sp.in/butler/public/uploadimage/getimage",
            contentType:"image/png",
            dataType:"json",
            data:formData,
            success:function(uploaded){
                console.info(uploaded.status);
            },
            error:function(error){
                                    console.info(error);    
                                             
            }
        });
    
}

I am trying to upload an image using AJAX. I have the local URL of my image and I want to pass that image as a file to the web service to upload.

Suppose i have the local file URL as : file:///accounts/1000/shared/camera/IMG_00000322.jpg

Now using AJAX I want to pass this to webservice, What will be the best way to do this? I also want show the progress while uploading

Using php in server side.

uploadImage : function(myImageUrl,chatId){

    var formData = new FormData();
    formData.append("chatId", chatId);
    formData.append("fileimage", myImageUrl);
    
        $.ajax(
        {
            type:"POST",
            url:"http://suresh.sp.in/butler/public/uploadimage/getimage",
            contentType:"image/png",
            dataType:"json",
            data:formData,
            success:function(uploaded){
                console.info(uploaded.status);
            },
            error:function(error){
                                    console.info(error);    
                                             
            }
        });
    
}
Source Link
Bora
  • 1.9k
  • 3
  • 28
  • 56

Upload Image Using AJAX with Progress Indicator

I am trying to upload an image using AJAX where i have the local URL of my image and i want to pass that image as a file to web service to upload.

Suppose i have the local file URL as : file:///accounts/1000/shared/camera/IMG_00000322.jpg

Now using AJAX i want to pass this to webservice, What will be the best way to do this, also i want show the progress. While uploading

Using php in server side.

uploadImage : function(myImageUrl,chatId){

    var formData = new FormData();
    formData.append("chatId", chatId);
    formData.append("fileimage", myImageUrl);
    
        $.ajax(
        {
            type:"POST",
            url:"http://suresh.sp.in/butler/public/uploadimage/getimage",
            contentType:"image/png",
            dataType:"json",
            data:formData,
            success:function(uploaded){
                console.info(uploaded.status);
            },
            error:function(error){
                                    console.info(error);    
                                             
            }
        });
    
}