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

rest_upload_no_data issue #344

Closed
cungminh2710 opened this issue Oct 30, 2017 · 3 comments · Fixed by #418
Closed

rest_upload_no_data issue #344

cungminh2710 opened this issue Oct 30, 2017 · 3 comments · Fixed by #418

Comments

@cungminh2710
Copy link

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

@mvhirsch
Copy link

mvhirsch commented Apr 8, 2018

I have the same problem. Anyone can help with a working example on how to use Buffer?

@mvhirsch
Copy link

mvhirsch commented Apr 8, 2018

@cungminh2710 I just ran into the same issue. I was able to solve it by applying a filename as second parameter: wp.media().file(buffer, 'image.jpg').create(fileOption).

Hope this helps.

Greets, Michael

@kadamwhite
Copy link
Collaborator

Thank you @cungminh2710 for raising the issue, and @mvhirsch for identifying the problem. We will be shipping an improved error notification for this situation in the upcoming v1.2.2 release so that it is more obvious that name is required when passing .file() a Buffer object. We have also expanded the documentation with a note about the issue.

I appreciate your support!

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

Successfully merging a pull request may close this issue.

3 participants