Giter Club home page Giter Club logo

Comments (5)

mikebilly avatar mikebilly commented on May 26, 2024 1

Hi @mikebilly

Good catch! Can I ask how you have found this header X-Goog-Upload-Name? Is there any documentation regarding it?

I tried to follow this Google documentation, where It doesn't know anything about the X-Goog-Upload-Name.

Thanks for submitting the bug and the fix 😍

@pacoorozco I was reading the tutorial at: https://learndataanalysis.org/upload-media-items-google-photos-api-and-python-part-4/, and I saw that he used headers['X-Goog-Upload-File-Name'] = 'Kuma_The_Corgi.jpg'

image_dir = os.path.join(os.getcwd(), 'Images To Upload')
upload_url = 'https://photoslibrary.googleapis.com/v1/uploads'
token = pickle.load(open('token_photoslibrary_v1.pickle', 'rb'))

headers = {
    'Authorization': 'Bearer ' + token.token,
    'Content-type': 'application/octet-stream',
    'X-Goog-Upload-Protocol': 'raw'
}

image_file = os.path.join(image_dir, 'Kuma.jpg')
headers['X-Goog-Upload-File-Name'] = 'Kuma_The_Corgi.jpg'

img = open(image_file, 'rb').read()
response = requests.post(upload_url, data=img, headers=headers)

request_body  = {
    'newMediaItems': [
        {
            'description': 'Kuma the corgi',
            'simpleMediaItem': {
                'uploadToken': response.content.decode('utf-8')
            }
        }
    ]
}

upload_response = service.mediaItems().batchCreate(body=request_body).execute()

For this, I had to create a fork of gphotos-uploader-cli and google-photos-api-client-go to use the modification, and saw that it worked.

from gphotos-uploader-cli.

mikebilly avatar mikebilly commented on May 26, 2024

I've found the fix, the problem is in https://github.com/gphotosuploader/google-photos-api-client-go:

Every X-Goog-Upload-Name must be changed to X-Goog-Upload-File-Name then it can get the correct filename.

For example, in google-photos-api-client-go/uploader/uploader_simple.go, change:

req.Header.Set("X-Goog-Upload-Name", upload.Name)

to:

req.Header.Set("X-Goog-Upload-File-Name", upload.Name)

from gphotos-uploader-cli.

mikebilly avatar mikebilly commented on May 26, 2024

@pacoorozco please take a look at https://github.com/gphotosuploader/google-photos-api-client-go and examine whether changing X-Goog-Upload-Name to X-Goog-Upload-File-Name is compulsory.

from gphotos-uploader-cli.

pacoorozco avatar pacoorozco commented on May 26, 2024

Hi @mikebilly

Good catch! Can I ask how you have found this header X-Goog-Upload-Name? Is there any documentation regarding it?

I tried to follow this Google documentation, where It doesn't know anything about the X-Goog-Upload-Name.

Thanks for submitting the bug and the fix 😍

from gphotos-uploader-cli.

pacoorozco avatar pacoorozco commented on May 26, 2024

I've found that the PHP library provided by Google use the header X-Goog-Upload-File-Name, even it says that it's not longer recommended.

The Java library is using it too.

from gphotos-uploader-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.