node-adwords icon indicating copy to clipboard operation
node-adwords copied to clipboard

Unable to upload image

Open actuallymentor opened this issue 6 years ago • 1 comments

Thanks for writing this node wrapper.

I'm trying to...

I'm trying to create a display ad with an image. Currently I managed to:

  • [x] Making budget
  • [x] Making a campaign
  • [x] Making an ad group
  • [ ] Uploading an image
    • note: ideally I'd just supply a url for the ad image but the docs seem to insist I need to use the Image type which uses base64 data
  • [ ] Creating an ad with the image

My current approach is:

const request = require( 'request-promise-native' )
const api = new AdwordsUser( { ... } )
const uploadImage = url => new Promise( async ( resolve, reject ) => {

	const mediaService = api.getService('MediaService', 'v201809')

	let imgSrc = {
		'xsi:type': 'Image',
		type: 'IMAGE',
		name: 'Generic' + ' - ' + Date.now(),
		data: Buffer.from( await request( url ), 'binary' ).toString( 'base64' )
    }

    mediaService.upload( { media: [ imgSrc ] }, ( error, img ) => error ? reject( error ) : resolve( img.value[0] ) )

} )

The unexpected result...

Which results in:

{"faultcode":"soap:Client","faultstring":"[ImageError.INVALID_IMAGE @ media[0].data]","detail":{"ApiExceptionFault":{"message":"[ImageError.INVALID_IMAGE @ media[0].data]","ApplicationException.Type":"ApiException","errors":{"attributes":{"xsi:type":"ImageError"},"fieldPath":"media[0].data","fieldPathElements":[{"field":"media","index":0},{"field":"data"}],"trigger":"","errorString":"ImageError.INVALID_IMAGE","ApiError.Type":"ImageError","reason":"INVALID_IMAGE"}}}}

I've tried...

  • [x] I looked at #66 but it didn't solve my issue.
  • [x] Send binary data to instead of base64 (error)
  • [x] using multiple jpeg URLs (confirmed to be valid)
  • [x] printed the result of toString('base64') to my console to manually check validity
  • [x] Buffer.from encoding as binary and utf8

If there is any useful information I can share let me know.

actuallymentor avatar Sep 17 '19 15:09 actuallymentor

+1

SacDin avatar Jan 08 '20 14:01 SacDin