GET media/upload "page does not exist"

restapi
media
media-upload
api

#1

I’m able to use the chunked media/upload endpoint to upload videos above 15MB without any problems.

But when I try to get the status of the upload, I get an error:

{"errors":[{"message":"Sorry, that page does not exist","code":34}]}

I used the signature generator (and switched in the correct media_id) to ensure my status request was accurate. What exactly is going on here, is this still a valid endpoint?


#2

I’m not aware of any issues with the upload endpoint at the moment. We have a handy sample for the chunked large file upload which steps through how to do this without needing to use a the signature generator, in case that is useful.


#3

EDIT: My mistake - this seems alright. I wasn’t waiting long enough after FINALIZE to check the status.

Thanks for sharing that example!

I had wrestled with the ‘media_category’ parameter for a bit and saw in your example that you used 'media_category': 'tweetvideo' instead of 'media_category': 'tweet_video'. I’ve seen both mentioned - which should be used?

After reviewing your example, I believe my code is aligned with the example, as I get the correct response for the 3 phases. That being said, calling status before and after the ‘check_after’ time I get a 400 error, as mentioned in the title.

Here’s my function:

async function postMediaChunked(twitterClient, file) {
  return await new Promise(async (resolve, reject) => {
    const { err, data } = await twitterClient.post('media/upload', {
      command: 'INIT',
      media_type: file.mime,
      media_category: parseMediaCategory(file.mime),
      total_bytes: fs.statSync(file.path).size
    })
    if (err) reject(err)

    var mediaIdStr = data.media_id_string
    let isStreamingFile = true
    let isUploading = false
    let segmentIndex = 0
    const fStream = fs.createReadStream(file.path, { highWaterMark: 1 * 1024 * 1024 })

    fStream.on('data', async function (buff) {
      fStream.pause()

      isUploading = true
      const { data } = await twitterClient.post('media/upload', {
        command: 'APPEND',
        media_id: mediaIdStr,
        segment_index: segmentIndex,
        media: buff.toString('base64')
      })
      isUploading = false

      if (!isStreamingFile && !isUploading) {
        _finalizeMedia(mediaIdStr)
      }
      fStream.resume()
      segmentIndex++
    })

    fStream.on('end', function () {
      isStreamingFile = false
      if (!isUploading && !isStreamingFile) {
        _finalizeMedia(mediaIdStr)
      }
    })

    const _finalizeMedia = async function (mediaIdStr) {
      const { data } = await twitterClient.post('media/upload', {
        'command': 'FINALIZE',
        'media_id': mediaIdStr
      })
      console.log('FINALIZE:', data)
      console.log('============')
      resolve(data)
    }
  })
}