0

I am trying to convert string to blob but I keep getting {} instead

const workingCSV = "Hey, hello, world,"
const localVue = createLocalVue()
const wrapper = shallowMount(ModalAddCollectionCSV, {
  localVue,
  propsData: {
    visible: true,
  },
})
const fileDict = [{ file: new Blob([workingCSV]) }]

fileDict is always [{file:{}}], I need it in that format because loadcsv reads the first file passed to it, but here the first file is always empty

1 Answer 1

0

You should create your blob in this way:

const csvData = [
  ['UPC', 'SKU', 'Description', 'Cost', 'Quantity', 'Bin location', 'Category', 'Primary supplier', 'Value'].join(';') // header row with names of the columns
].concat(originalItemsArray.map(item => [ // only extract the columns we need
  item.upc,
  item.sku,
  item.product_name,
  +item.cost || 0,
  +item.level || 0,
  item.bin_location,
  item.category_name,
  item.supplier_name,
  (+item.level || 0) * (+item.cost || 0),
].map(val => JSON.stringify(val)).join(';'))); // properly quote the value of each column

  const myBlob = new Blob([csvData.join('\r\n')], { type: 'text/csv;charset=cp1250;' }); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.