0

I would like to take an image's URL and use that to get the image file object and send it to my server. i have looked around and have gotten this far but the code does not work properly. When i send it to my server it does not upload as an image file but simply uploads as a file without the .JPG extension or any image file extension.

    var byteNumbers = new Array(this.imgUrl.length);

    for (var i = 0; i < this.imgUrl.length; i++)
    {
        byteNumbers[i] = this.imgUrl.charCodeAt(i);
    }

    this.img = new File(byteNumbers, "imgFromUrl", { type: "image/jpeg" });  

This gets the file and shows me the file details on my log such as lastmodified, filename and such. but when i upload it to my server i just get a file with no extension as mentioned above.

The file is being uploaded by being attached to a form and sent to the server.This is because i'm sending other data as well.

this.http.post(this.serverUrl + "face/detect/", data, { headers: this.headers })
          .toPromise()
          .then(response => response.json())
          .catch(error => error);
lagfvu
  • 597
  • 6
  • 21
  • please share the code that you're using to upload the file to your server – Patrick Hund Mar 07 '17 at 09:34
  • @PatrickHund i know the server code works because i have a file-picker using the same code and that works fine. but i want to be able to paste in a url of an image and upload that image. – lagfvu Mar 07 '17 at 09:38
  • http://stackoverflow.com/questions/12405197/read-process-image-through-javascript-by-passing-its-url-similar-to-file-get check this one if it helps :) – Dhaval Chaudhary Mar 07 '17 at 09:57

1 Answers1

0

You would need to specify the extention in the file name

 var byteNumbers = new Array(this.imgUrl.length);

    for (var i = 0; i < this.imgUrl.length; i++)
    {
        byteNumbers[i] = this.imgUrl.charCodeAt(i);
    }

    this.img = new File(byteNumbers, "imgFromUrl.jpg", { type: "image/jpeg" }); 

Tell me if this solves the problem.

CaptainHere
  • 698
  • 6
  • 14