Home  >  Q&A  >  body text

javascript - Can cross-domain download files with a tag be renamed?

Can cross-domain download files with a tag be automatically renamed when clicking download?
The file is not on my server
I don’t want to save this file on my server
Is there a way for users to automatically rename the file name when downloading by clicking the a tag?

过去多啦不再A梦过去多啦不再A梦2676 days ago1614

reply all(2)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-24 11:35:26

    You can use the HTML5中的download attribute, refer to w3school:

    <a href="https://www.baidu.com/img/bd_logo1.png" download="baidu">
    

    Attached is a cross-domain solution

    Nginx (Same as Apache):

    location /imgProxy {
        resolver 10.0.0.1;
        proxy_pass $arg_url;
    }

    <a href="/imgProxy?url=https://static.segmentfault.com/v-5922866b/global/img/logo-b.svg" download="logo">segmentfault</a> 
    

    reply
    0
  • PHPz

    PHPz2017-05-24 11:35:26

    Currently only Chrome supports this feature:

    <a href="..." download="file.mp4">Download</a>

    reply
    0
  • Cancelreply