如何在JavaScrip中定义本地文件的路径

2024-09-30 12:20:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在运行Microsoft Azures计算机视觉OCR使用JavaScript,只能上传带有HTML地址的图像。你知道吗

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

我想从本地源上传图像以复制此python代码:

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

这可能吗?如果可能,怎么可能?你知道吗


Tags: path图像imagevar地址html计算机视觉
3条回答

请尝试以下代码:

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

它将从用户的桌面选择一个文件。你知道吗

您可以尝试使用“文件”协议:file:///Users/FelixWallis/Desktop/Flask_t1/files/my_image.jpg

或者使用启动本地web服务器并将文件添加到静态文件中。你知道吗

不,不要那样做。我假设您有一个类型为文件的输入元素。你知道吗

   //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});

你也可以upload a file with Node。你知道吗

相关问题 更多 >

    热门问题