douce1368 2017-08-18 19:45
浏览 8

如何将文件上传到网址服务器,其名称在网址中

I want to upload an image from my phone via an app to the server.

Using PHP I always have to submit a form but I can't, since I just call open a link: http://xxx.yy/?file=C:/xxx/yyy/zzz.png

Do I have any other possibilities to upload an image from an android application to a webserver?

How do I upload the file with the filepath given in the URL?

  • 写回答

1条回答 默认 最新

  • doufu6130 2017-08-18 21:10
    关注

    You can request the file from local filesystem as a Blob using XMLHttpRequest() or fetch() utilize FileReader to convert the Blob to a data URI, set the .href property of an <a> element to path to server with query string where data URI is value of query, call .click() on <a> element. At server process query string parameters at GET request to process data URI representation of file.

    const a = document.createElement("a");
    document.body.appendChild(a);
    const reader = new FileReader;
    reader.onload = () => {
      a.href = `/path/to/server?file=${reader.result}`;
      a.click();
    }
    
    fetch("/path/to/local/file")
    .then(response => response.blob())
    .then(blob => reader.readAsDataURL(blob))
    .catch(err => console.error(err));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题