How to download in-memory file object in Javascript?How do I check whether a file exists without exceptions?How do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?How do I redirect to another webpage?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

What is the evidence on the danger of feeding whole blueberries and grapes to infants and toddlers?

Unbiased estimator of exponential of measure of a set?

How does the Saturn V Dynamic Test Stand work?

90s(?) book series about two people transported to a parallel medieval world, she joins city watch, he becomes wizard

Is it allowable to use an organization's name to publish a paper in a conference, even after I graduate from it?

Label on a bended arrow

Does the Symbiotic Entity damage apply to a creature hit by the secondary damage of Green Flame Blade?

Can others monetize my project with GPLv3?

But though we be the children of technology

Moons that can't see each other

Chess software to analyze games

I think my coworker went through my notebook and took my project ideas

Interaction between Ethereal Absolution versus Edgar Markov with Captivating Vampire

How much code would a codegolf golf if a codegolf could golf code?

Are there categories whose internal hom is somewhat 'exotic'?

What is the latest version of SQL Server native client that is compatible with Sql Server 2008 r2

Has there ever been a truly bilingual country prior to the contemporary period?

How to dismiss intrusive questions from a colleague with whom I don't work?

Can my Boyfriend, who lives in the UK and has a Polish passport, visit me in the USA?

Chord with lyrics - What does it mean if there is an empty space instead of a Chord?

Are there reliable, formulaic ways to form chords on the guitar?

Why would the President need briefings on UFOs?

Are required indicators necessary for radio buttons?

Why don't politicians push for fossil fuel reduction by pointing out their scarcity?



How to download in-memory file object in Javascript?


How do I check whether a file exists without exceptions?How do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?How do I redirect to another webpage?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have an in-memory file object like this in Javascript:




name: "1_mRf78VMrVHjBMQpz6PYmiw.jpeg",
lastModified: 1549023843303,
lastModifiedDate: Fri Feb 01 2019 17:54:03 GMT+0530 (India Standard Time),
webkitRelativePath: "",
size: 265437,



How can I download it?



var link = document.createElement("a");
document.body.appendChild(link);
link.download =element.artifactName;//file name
link.href = element.artifact;//file object
link.click();


It is downloading corrupted file instead of original file.










share|improve this question


























  • You need to create an object URL out of your File instance first, and assign that as the link href. developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL

    – 04FS
    Mar 27 at 12:13











  • Thanks worked like a charm.

    – ABHISHEK BHARDWAJ
    Mar 27 at 12:19






  • 1





    Please add the actual solution below for everyone to benefit. Thank you.

    – programmer-man
    Mar 27 at 12:32

















0















I have an in-memory file object like this in Javascript:




name: "1_mRf78VMrVHjBMQpz6PYmiw.jpeg",
lastModified: 1549023843303,
lastModifiedDate: Fri Feb 01 2019 17:54:03 GMT+0530 (India Standard Time),
webkitRelativePath: "",
size: 265437,



How can I download it?



var link = document.createElement("a");
document.body.appendChild(link);
link.download =element.artifactName;//file name
link.href = element.artifact;//file object
link.click();


It is downloading corrupted file instead of original file.










share|improve this question


























  • You need to create an object URL out of your File instance first, and assign that as the link href. developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL

    – 04FS
    Mar 27 at 12:13











  • Thanks worked like a charm.

    – ABHISHEK BHARDWAJ
    Mar 27 at 12:19






  • 1





    Please add the actual solution below for everyone to benefit. Thank you.

    – programmer-man
    Mar 27 at 12:32













0












0








0








I have an in-memory file object like this in Javascript:




name: "1_mRf78VMrVHjBMQpz6PYmiw.jpeg",
lastModified: 1549023843303,
lastModifiedDate: Fri Feb 01 2019 17:54:03 GMT+0530 (India Standard Time),
webkitRelativePath: "",
size: 265437,



How can I download it?



var link = document.createElement("a");
document.body.appendChild(link);
link.download =element.artifactName;//file name
link.href = element.artifact;//file object
link.click();


It is downloading corrupted file instead of original file.










share|improve this question
















I have an in-memory file object like this in Javascript:




name: "1_mRf78VMrVHjBMQpz6PYmiw.jpeg",
lastModified: 1549023843303,
lastModifiedDate: Fri Feb 01 2019 17:54:03 GMT+0530 (India Standard Time),
webkitRelativePath: "",
size: 265437,



How can I download it?



var link = document.createElement("a");
document.body.appendChild(link);
link.download =element.artifactName;//file name
link.href = element.artifact;//file object
link.click();


It is downloading corrupted file instead of original file.







javascript file






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 14:52









MarredCheese

4,1214 gold badges28 silver badges45 bronze badges




4,1214 gold badges28 silver badges45 bronze badges










asked Mar 27 at 12:10









ABHISHEK BHARDWAJABHISHEK BHARDWAJ

951 silver badge11 bronze badges




951 silver badge11 bronze badges















  • You need to create an object URL out of your File instance first, and assign that as the link href. developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL

    – 04FS
    Mar 27 at 12:13











  • Thanks worked like a charm.

    – ABHISHEK BHARDWAJ
    Mar 27 at 12:19






  • 1





    Please add the actual solution below for everyone to benefit. Thank you.

    – programmer-man
    Mar 27 at 12:32

















  • You need to create an object URL out of your File instance first, and assign that as the link href. developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL

    – 04FS
    Mar 27 at 12:13











  • Thanks worked like a charm.

    – ABHISHEK BHARDWAJ
    Mar 27 at 12:19






  • 1





    Please add the actual solution below for everyone to benefit. Thank you.

    – programmer-man
    Mar 27 at 12:32
















You need to create an object URL out of your File instance first, and assign that as the link href. developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL

– 04FS
Mar 27 at 12:13





You need to create an object URL out of your File instance first, and assign that as the link href. developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL

– 04FS
Mar 27 at 12:13













Thanks worked like a charm.

– ABHISHEK BHARDWAJ
Mar 27 at 12:19





Thanks worked like a charm.

– ABHISHEK BHARDWAJ
Mar 27 at 12:19




1




1





Please add the actual solution below for everyone to benefit. Thank you.

– programmer-man
Mar 27 at 12:32





Please add the actual solution below for everyone to benefit. Thank you.

– programmer-man
Mar 27 at 12:32












1 Answer
1






active

oldest

votes


















0














this worked



var link = document.createElement("a");
var file = element.artifact;

link.download = element.artifactName;
link.href = URL.createObjectURL(file);
link.click();





share|improve this answer


























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55376879%2fhow-to-download-in-memory-file-object-in-javascript%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    this worked



    var link = document.createElement("a");
    var file = element.artifact;

    link.download = element.artifactName;
    link.href = URL.createObjectURL(file);
    link.click();





    share|improve this answer































      0














      this worked



      var link = document.createElement("a");
      var file = element.artifact;

      link.download = element.artifactName;
      link.href = URL.createObjectURL(file);
      link.click();





      share|improve this answer





























        0












        0








        0







        this worked



        var link = document.createElement("a");
        var file = element.artifact;

        link.download = element.artifactName;
        link.href = URL.createObjectURL(file);
        link.click();





        share|improve this answer















        this worked



        var link = document.createElement("a");
        var file = element.artifact;

        link.download = element.artifactName;
        link.href = URL.createObjectURL(file);
        link.click();






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 27 at 15:00









        Rastalamm

        1,0421 gold badge13 silver badges26 bronze badges




        1,0421 gold badge13 silver badges26 bronze badges










        answered Mar 27 at 12:43









        ABHISHEK BHARDWAJABHISHEK BHARDWAJ

        951 silver badge11 bronze badges




        951 silver badge11 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55376879%2fhow-to-download-in-memory-file-object-in-javascript%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Obelisk of Theodosius Contents History Description Notes Bibliography Further reading External links Navigation menuAge of spirituality : late antique and early Christian art, third to seventh centuryOver 60 picturesObelisks of the World41°00′21.24″N 28°58′31.43″E / 41.0059000°N 28.9753972°E / 41.0059000; 28.97539727724550-7235741376235741376

            밀양 대씨 역사 각주 함께 보기 둘러보기 메뉴밀양 대씨

            1973년 목차 사건 문화 탄생 사망 노벨상 달력 둘러보기 메뉴