Skip to content

rest_upload_no_data issue #344

Description

@cungminh2710

I had a piece of NodeJs code that retrieve buffer from a image URL then upload to Wordpress using wp.media().

const axios = require('axios');
// Setting up wordpress library and auth 
const wordpress = require('wpapi');
const wp = new wordpress(auth);

let retrieveImageBuffer = url => axios
		.get(url, {
			responseType: "arraybuffer"
		})
		.then(response => Promise.resolve(new Buffer(response.data, "binary")));
}

let run = async (url, fileOption) => {
                let buffer = await retrieveImageBuffer(url);
		try {
			let result = await wp
				.media()
				.file(buffer)
				.create(fileOption);
		} catch (err) {
			console.log(err.message);
		}
}

run(url, fileOption);

What I get after running the script: Error: No data supplied

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions