Skip to content

Text Works, Images Not So Much #33

@gregphillips03

Description

@gregphillips03

I have the following sitting in the AWS cloud API Gateway:

import Twitter from "twitter-lite"; 
import { success, failure } from "./libs/response-lib";

export async function main(event, context, callback) {
  const data = JSON.parse(event.body);
  const client = new Twitter({
    subdomain: "api",
    consumer_key: "redacted"
    consumer_secret: "redacted"
    access_token_key: "redacted"
    access_token_secret: "redacted"
  });

  if(data.base64encodedimg)
  {
    try 
    {
      client.subdomain = "upload"; 
      const url = await client.post("media/upload", null, {
        media_data: data.base64encodedimg,
      }); 
      client.subdomain ="api";
      await client.post("statuses/update", null, {
        status: data.tweet,
        media_ids: url.media_id_string,
      });
    } catch (e) {
      console.log(e); 
      callback(null, failure({ status: false }));
    }
  } 
  else 
  {
    try 
    {
      await client.post("statuses/update", null, {
        status: data.tweet,
      });   
      callback(null, success(data.tweet));
    } catch (e) {
      console.log(e); 
      callback(null, failure({ status: false }));
    }
  }

}

I can fire off tweets all day long with a problem, but I'm not able to attach an image to them. Tweeting without an image works without a hitch as well.
I've gone through the painful process of ensuring that I'm actually sending along a base64 encoded image, so I know that's coming through as expected, at least to the gateway.
When this fails, all I receive back is a 500 response.
Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions