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

Unable to upload image #99

Open
8 of 10 tasks
actuallymentor opened this issue Sep 17, 2019 · 1 comment
Open
8 of 10 tasks

Unable to upload image #99

actuallymentor opened this issue Sep 17, 2019 · 1 comment

Comments

@actuallymentor
Copy link

actuallymentor commented Sep 17, 2019

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:

  • Making budget
  • Making a campaign
  • 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...

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

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

@SacDin
Copy link

SacDin commented Jan 8, 2020

+1

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