Click here to Skip to main content
15,881,757 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionOpen base64 encoded pdf file using javascript Pin
Member 1286358021-Oct-19 4:16
Member 1286358021-Oct-19 4:16 
AnswerRe: Open base64 encoded pdf file using javascript Pin
jkirkerx21-Oct-19 12:22
professionaljkirkerx21-Oct-19 12:22 
AnswerRe: Open base64 encoded pdf file using javascript Pin
Richard Deeming22-Oct-19 1:15
mveRichard Deeming22-Oct-19 1:15 
GeneralRe: Open base64 encoded pdf file using javascript Pin
jkirkerx24-Oct-19 12:18
professionaljkirkerx24-Oct-19 12:18 
AnswerRe: Open base64 encoded pdf file using javascript Pin
Parth Munjpara22-Oct-19 23:11
Parth Munjpara22-Oct-19 23:11 
QuestionWant to download a zip file that's returned as FileStreamResult only, I could able to download in-memory using byte array but Pin
simpledeveloper17-Oct-19 13:27
simpledeveloper17-Oct-19 13:27 
AnswerRe: Want to download a zip file that's returned as FileStreamResult only, I could able to download in-memory using byte array but Pin
jkirkerx21-Oct-19 12:11
professionaljkirkerx21-Oct-19 12:11 
GeneralRe: Want to download a zip file that's returned as FileStreamResult only, I could able to download in-memory using byte array but Pin
simpledeveloper21-Oct-19 13:16
simpledeveloper21-Oct-19 13:16 
Thank you jkikerx, I did it in the following way, its completed ready to demo (just in case if somebody wants implement this I am putting my implementation here) - thanks for jumping in to help me.
Here is Web Api code C#:
[EnableCors("AnotherPolicy")]
        [HttpPost]
        public FileStreamResult Post([FromForm] string communityName, [FromForm] string files) //byte[]
        {
            var removedInvalidCharsFromFileName = removeInvalidCharsFromFileName(files);
            var tFiles = removedInvalidCharsFromFileName.Split(',');
            string rootPath = Configuration.GetValue<string>("ROOT_PATH");
            string communityPath = rootPath + "\\" + communityName;

            MemoryStream zipStream = new MemoryStream();

            using (ZipArchive zip = new ZipArchive(zipStream, ZipArchiveMode.Create, true))
            {
                foreach (string attachment in tFiles)
                {
                    var zipEntry = zip.CreateEntry(attachment);

                    using (FileStream fileStream = new FileStream(communityPath + "\\" + attachment, FileMode.Open))
                    {
                        using (Stream entryStream = zipEntry.Open())
                        {
                            fileStream.CopyTo(entryStream);
                        }
                    }
                }
            }

            zipStream.Position = 0;

            return File(zipStream, "application/octet-stream");
        }

Then my client side React code is here:
handleDownload = (e) => {
        e.preventDefault();

        var formData = new FormData();
        formData.append('communityname', this.state.selectedCommunity);
        formData.append('files', JSON.stringify(this.state['checkedFiles']));

        //let env='local';        
        let url = clientConfiguration['filesApi.local'];
        //let tempFiles = clientConfiguration[`tempFiles.${env}`];
        //alert(tempFiles);

        axios({
            method: 'post',
            responseType: 'arraybuffer', //Force to receive data in a Blob Format
            url: url,
            data: formData
        })
            .then(res => {
                let extension = 'zip';
                let tempFileName = `${this.state['selectedCommunity']}`
                let fileName = `${tempFileName}.${extension}`;

                const blob = new Blob([res.data], {
                    type: 'application/octet-stream'
                })

                saveAs(blob, fileName)
            })
            .catch(error => {
                console.log(error.message);
            });
    };

this event is called when button is clicked or form submitted. Thanks for all the support the SO has given - thanks a lot.
GeneralRe: Want to download a zip file that's returned as FileStreamResult only, I could able to download in-memory using byte array but Pin
jkirkerx22-Oct-19 7:21
professionaljkirkerx22-Oct-19 7:21 
GeneralRe: Want to download a zip file that's returned as FileStreamResult only, I could able to download in-memory using byte array but Pin
simpledeveloper22-Oct-19 8:56
simpledeveloper22-Oct-19 8:56 
GeneralRe: Want to download a zip file that's returned as FileStreamResult only, I could able to download in-memory using byte array but Pin
jkirkerx23-Oct-19 6:55
professionaljkirkerx23-Oct-19 6:55 
GeneralRe: Want to download a zip file that's returned as FileStreamResult only, I could able to download in-memory using byte array but Pin
simpledeveloper24-Oct-19 13:25
simpledeveloper24-Oct-19 13:25 
Questionhas been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource Pin
simpledeveloper15-Oct-19 13:05
simpledeveloper15-Oct-19 13:05 
AnswerRe: has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource Pin
jkirkerx15-Oct-19 13:54
professionaljkirkerx15-Oct-19 13:54 
AnswerRe: has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource Pin
F-ES Sitecore15-Oct-19 22:14
professionalF-ES Sitecore15-Oct-19 22:14 
AnswerRe: has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource Pin
simpledeveloper16-Oct-19 7:10
simpledeveloper16-Oct-19 7:10 
QuestionTrying to download Zip files that's returned from Api React Pin
simpledeveloper14-Oct-19 9:00
simpledeveloper14-Oct-19 9:00 
AnswerRe: Trying to download Zip files that's returned from Api React Pin
Richard Deeming14-Oct-19 9:38
mveRichard Deeming14-Oct-19 9:38 
GeneralRe: Trying to download Zip files that's returned from Api React Pin
simpledeveloper14-Oct-19 11:45
simpledeveloper14-Oct-19 11:45 
GeneralRe: Trying to download Zip files that's returned from Api React Pin
Richard Deeming15-Oct-19 1:24
mveRichard Deeming15-Oct-19 1:24 
GeneralRe: Trying to download Zip files that's returned from Api React Pin
simpledeveloper15-Oct-19 6:31
simpledeveloper15-Oct-19 6:31 
GeneralRe: Trying to download Zip files that's returned from Api React Pin
simpledeveloper15-Oct-19 8:59
simpledeveloper15-Oct-19 8:59 
GeneralRe: Trying to download Zip files that's returned from Api React Pin
Richard Deeming16-Oct-19 7:49
mveRichard Deeming16-Oct-19 7:49 
GeneralRe: Trying to download Zip files that's returned from Api React Pin
simpledeveloper17-Oct-19 6:53
simpledeveloper17-Oct-19 6:53 
GeneralRe: Trying to download Zip files that's returned from Api React Pin
Richard Deeming17-Oct-19 7:12
mveRichard Deeming17-Oct-19 7:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.