Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (29 sloc) 1.47 KB
title
Upload Asset

Uploading assets in Storyblok is a two step process. First you need to sign the asset you want to upload. Then you need to post the image as form data to our Amazon S3 bucket. Uploaded files will have parameterized names; Every dot "." (except the last one) will be replaced with underscore "_";

Here you can find an example using Node.js on Github.

;examplearea

  1. Start by requesting a signed upload URL and parameter

Example Request

  1. Use the received signed response object to upload your file (example uses Node.js):
const FormData = require('form-data')
const fs = require('fs')

const file = '/path_to/your_file.jpg'
const fileUpload = (signed_response_object, success, failed) => {
  let form = new FormData()
  // apply all fields from the signed response object to the second request
  for (let key in signed_response_object.fields) {
    form.append(key, signed_response_object.fields[key])
  }
  // also append the file read stream
  form.append('file', fs.createReadStream(file))
  // submit your form
  form.submit(signed_response_object.post_url, (err, res) => {
    if (err) throw err
    console.log('https://a.storyblok.com/' + signed_response_object.fields.key + ' uploaded!')
  })
}