Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is there any endpoint to upload an image to medium #40

Open
shivaypiece opened this issue Oct 18, 2023 · 1 comment
Open

is there any endpoint to upload an image to medium #40

shivaypiece opened this issue Oct 18, 2023 · 1 comment

Comments

@shivaypiece
Copy link

I have all my blog images locally.
when automatically publishing to the Medium blogs by uploading these images. can you expose an endpoint in the nodejs SDK.

This is the https://github.com/Medium/medium-api-docs#34-images is here. can you add it to the SDK

@wscourge
Copy link

wscourge commented Dec 26, 2023

Update: Using the npm i request library worked:

const filename = "image.jpeg"
const jpegpath = "/path/to/image.jpeg"

request({
    method: "POST",
    url,
    headers: {
      ...headers,
      "Content-Type": "multipart/form-data",
      "Content-Disposition": `form-data; name="image"; filename="${filename}"`
    },
    formData: { image: fs.createReadStream(jpegpath) },
  }, (err, res, body) => {
    console.log("err:", err)
    console.log("res:", res)
    console.log("body:", body)
  })

I was not able to do this using axios and form-data so far, but it worked the first time I tried with curl:

curl -X POST -H "Authorization: Bearer <TOKEN>" -F "image=@/path/to/image.jpeg" https://api.medium.com/v1/images

I hope it helps someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants