Cypress upload file gives error Failed to execute 'atob' on 'Window' - cypress

cy.fixture('invitati100.xls').as('logo')
cy.get('[name="fileLista"]').then(function($input) {
// convert the logo base64 string to a blob
return Cypress.Blob.base64StringToBlob(this.logo, 'application/vnd.ms-excel')
.then((blob) => {
// pass the blob to the fileupload jQuery plugin
// used in your application's code
// which initiates a programmatic upload
$input.fileupload('add', { files: blob })
})
})
Gives error:
cypress_runner. : 159529 InvalidCharacterError: Failed to execute 'atob' on 'Window': The string to be decoded contains characters outside of the Latin1 range.
at http://platform/__cypress/runner/cypress_runner.js:1531:44
From previous event:
at Context.thenFn (http://platform/__cypress/runner/cypress_runner.js:69293:23)
We are using dojo as framework.
Why this error?
Thanks!

Just use this plug-in:
https://www.npmjs.com/package/cypress-file-upload
it's super easy and it works!

Related

Tabulator not downloading using Tabulator.download

Tabulator not downloading using Tabulator.download(). I have tried using CSV as well as xlsx format however no success. I am using the npm package in a react component. The data is visible in the table on UI.
It fails at the following function:
Download.prototype.downloaders = {
csv: function csv(columns, data, options, setFileContents, config)
The stack trace shown in the console is:
Cannot read property 'forEach' of undefined
at parseRows (tabulator.js:11677)
at Download.csv (tabulator.js:11722)
at Download.download (tabulator.js:11419)
at Tabulator.download (tabulator.js:8337)
Turns out this is an issue specific to the react version of tabulator. Found a solution here:
https://github.com/ngduc/react-tabulator/issues/76
Just add this to your options object:
options = {
downloadDataFormatter: (data) => data,
downloadReady: (fileContents, blob) => blob,
}

How to download any generated by JS file from firefox addon?

I need to my extension can generate and save text file inside downloads folder. Just give me example of code how to do it.
The downloads API is what you are probably looking for:
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/downloads
The downloads.download() function lets you download a file from a URL to your Downloads folder. Here is the example based on the Downloads.download() page.
function onStartedDownload(id) {
console.log('Started downloading: ' + id);
}
function onFailed(error) {
console.log('Download failed: ' + error);
}
var downloadUrl = "https://www.mozilla.org/media/img/home/2018/cards/irl-season-3.821df676279d.png";
var downloading = browser.downloads.download({
url : downloadUrl,
filename : 'mozilla-home.png',
conflictAction : 'uniquify'
});
downloading.then(onStartedDownload, onFailed);
If you need to download data created in Javascript, then you'll first have to create a URL for that data using URL.createObjectURL()

React-Native convert a base64 images array to a single pdf

I'm working on a mobile app in react-native / redux in which I have to convert an array of base64 images into a pdf in order to send the pdf to the back-end.
Any idea about how to achieve it ?
Ok I finally found an easy solution with the help of react-native-image-to-pdf
It is promis based. In a file I called "pdfConverter.js" I created this function
import RNImageToPdf from "react-native-image-to-pdf";
export default base64Arr => {
// It is a promise based function
// Create an array containing the path of each base64 images
let base64Paths = [];
base64Paths.length = 0; // re-initialize the array for further re-use
base64Arr.forEach(base64 => {
base64Paths.push(`data:image/jpeg;base64,${base64}`);
});
// Convert base64 images to pdf from the paths array
return RNImageToPdf.createPDFbyImages({
imagePaths: base64Paths,
name: "PDF_Name"
});
};
and then call it where I need in another file :
import toPDF from "./pdfConverter.js";
toPDF(myBase64array)
.then(pdf => {
console.log("pdf ", pdf);
});

MvcRazorToPdf How to download file using ajax call? MVC

I tried to use MvcRazorToPdf, i can able to generate mail merge letters. My aim is after downloading file i want to return json message from controller. how to do?
Controller: [how to convert the below lines to generate pdf and download without return]
return new PdfActionResult(pdfres, (writer, document) =>
{
document.SetPageSize(new Rectangle(PageSize.A4));
document.NewPage();
})
{
FileDownloadName = "ElanWasHere.pdf"
};
I appreciate your help. thanks

Getting original file meta-data from FineUploader

I am aware that performing a stat on an uploaded file will only give creation/modified/access dates at the time the file was uploaded.
So a very quick question, is there any way for FineUploader to access the original file meta-data for these fields and send it along with the upload request?
From what I understand, this is probably not possible, but it never hurts to ask!
This feature is not natively supported by Fine Uploader. You could open up an issue if you think it would be a useful feature.
That being said, you can do it using Fine Uploader's callbacks and the FileAPI. The best you could do in any browser right now is get the lastModifiedDate using the FileAPI and add that to the parameters for each file in your onSubmitted callback,
var getLastModifiedDate = function(file) {
/* Cross-broswer File API shim to get Last Modified Date of a file */
}
var fineuploader = new qq.FineUploader/* ... */
/* snippet */
callbacks: {
onSubmitted: function(id, name) {
var file = fineuploader.getFile(id),
lastModified = getLastModifiedDate(file);
fineuploader.setParams({ lastModified: lastModified }, id);
});
}
/* snippet */
I found this question and answer which has an example and a shim to retrieve the lastModifiedDate.

Resources