Contentful logo

Contentful Community

Errors when attempting to upload mp4 assets

#1

Hi!

I have a set of ~140 MP4s on google cloud storage that I need to get uploaded into Contentful. I have tried two approaches to doing so. These files are approx 50mb.

First approach using createUpload:

  1. I get a filestream from the google bucket using @google-cloud/storage.
  2. Send this as the file parameter on createUpload.

In this case I get:

[warning] Connection error occurred. Waiting for 1941 ms before retrying...
[warning] Connection error occurred. Waiting for 2669 ms before retrying...
[warning] Connection error occurred. Waiting for 3520 ms before retrying...

Running this with DEBUG=* I see it is trying to send the following request:

  protocol: 'https:',
  hostname: 'upload.contentful.com',
  port: '443',
  path: '/spaces/<spaceid>/uploads',
  method: 'post'

I don’t see any other details for what is occurring, what network response is coming back, etc.

Second approach using createAsset:

  1. Get a signed URL using google storage API
  2. Send the signed URL as the file['en-US'].upload property on createAsset.
  3. Publish the asset.

The signed URLs work fine with cURL. When the code tries to publish the asset at:

PUT https://api.contentful.com:443/spaces/<spaceid>/environments/master/assets/<assetid>/published

I get a 422: Unprocessable Entity error:

{
    "name": "noFileFields",
    "details": "The asset has no files"
}

If I try to now manually upload the file via the interface, by using the signed URL in the link, I get an upload error (no details). When I look at the network tab I see that there’s a GET request being made, 400 response, with this body:

validation error: task not found: "videos"

Is this a validation that someone on our side set up, or is it internal at Contentful? I don’t see a place where we can create/edit validations on media assets.

I’ve spent about 6 hours trying these different approaches. Can someone point me in the right direction? I prefer the createAsset approach because it doesn’t require me to soak up a bunch of bandwidth on my my personal connection downloading and uploading video files. But I think I need:

  1. Some way of polling the asset status for completion or error
  2. Resolution/more details on the upload errors that are occuring

Appreciate your time and thoughtfulness. Thanks!

0 Likes

#2

Hi @ops,

Before trying to create the actual assets, have you submitted requests to achieve what is described in the following section of our documentation?

https://www.contentful.com/developers/docs/references/content-management-api/#/reference/uploads

If so, in the process of uploading the file, could you try first storing it locally in your computer and then pass the file path into the request that is sent to our Upload API?

0 Likes

#3

@gabriel I noted above: when I call the upload endpoint I’m not getting any kind of usable response back. That is where I am getting:

[warning] Connection error occurred. Waiting for 1941 ms before retrying...

I get this same error if I create a readStream from a local file and pass it to the createUpload method. So it doesn’t seem like I can proceed to any further steps until I see some kind of success with the upload.

Again, I would prefer not to use createUpload at all, as it would save me bandwidth and development time if I could give contentful the signedUrl and have your servers perform the download. It seems like I need to call asset.process() within this flow… I will try that and get back to you.

0 Likes

#4

When I try to process the asset I get this error:

  "status": 422,
  "statusText": "Unprocessable Entity",
  "message": "Validation error",
  "details": {
    "errors": [
      {
        "name": "required",
        "path": [
          "fields",
          "file",
          "en-US"
        ],
        "details": "No file specified for locale: en-US"
      }
    ]

My code looks like this, you can see I’m putting my signed URL in for the upload property:

const asset = await contentful.createAsset({
  fields: {title: {'en-US': title}},
  file: {
    'en-US': {
      contentType: 'video/mp4',
      fileName,
      upload: signed_url,
    }
  }
})
const processed = await asset.processForLocale('en-US')
return processed.publish()

I’m following the example from here: https://contentful.github.io/contentful-management.js/contentful-management/latest/ContentfulEnvironmentAPI.html#.createAsset

What else can be done here?

0 Likes