1

I am running Microsoft Azures Computer Vision OCR using JavaScript and can only upload images with an HTML address.

var sourceImageUrl = document.getElementById("inputImage").value;
document.querySelector("#sourceImage").src = sourceImageUrl;

I would like to upload images from a local source to replicate this python code:

image_path = '/Users/FelixWallis/Desktop/Flask_t1/files'
image_data = open(image_path, "rb").read()

Is this possible, and if so how?

User863
  • 19,346
  • 2
  • 17
  • 41
Felix Wallis
  • 33
  • 1
  • 5

3 Answers3

0

No don't do that. I am assuming you have an input element with type as a file.

   //html code
  <input type="file" id="image-file" />   

 let image = document.getElementById("image-file").files[0];
let formData = new FormData();

formData.append("photo", photo);
fetch('/upload/image', {method: "POST", body: formData});

You can also upload a file with Node.

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Alcantara
  • 120
  • 7
  • Thank you for your suggestion. Unfortunately the image has to be in the form of a URL otherwise Microsoft Azure returns 'Bad Request (400): Invalid image URL.'. – Felix Wallis Sep 14 '19 at 12:30
0

Try this code :

image_path = 'file:///C:/Users/FelixWallis/Desktop/Flask_t1/files'

which will pick a file from the user's desktop.

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
  • Thank you for participating, Hugo :-) Notice someone edited your answer to provide an explanation as to how the proposed solution (code) would help solve the problem in the question. You can roll the change back, if you want - no one wants to step on your toes, but... On Stack Overflow it's preferred to provide some explanation, not just code, so that people understand and learn as well as get immediate help. – Cindy Meister Sep 14 '19 at 11:56
  • This was my first instinct, but unfortunately Microsoft azure does not support this – Felix Wallis Sep 14 '19 at 11:57
0

You can try to use the "file" protocol: file:///Users/FelixWallis/Desktop/Flask_t1/files/my_image.jpg

Or use launch a local web server and add the file to your static files.

BPS Julien
  • 126
  • 2
  • I did this using a web server and flask with the command @app.route('/get-picture/') def return_file(): return send_file('files.jpg'). This allowed me to access the image using http://**.***.*.***/get-picture/. However, when I used this URL for my sourceImageURL in Microsoft Azure, Computer vision could not process the image. – Felix Wallis Sep 14 '19 at 12:04