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

Uploads are showing date of upload as filename. #398

Closed
mikebilly opened this issue Oct 23, 2023 · 5 comments · Fixed by #399
Closed

Uploads are showing date of upload as filename. #398

mikebilly opened this issue Oct 23, 2023 · 5 comments · Fixed by #399
Assignees
Labels
bug Something isn't working fixed The bug has been fixed, but the fix is not permanent. Needs a refactor.

Comments

@mikebilly
Copy link

mikebilly commented Oct 23, 2023

Photos: Photo's names are named like 2023-10-23.jpg which is the day of upload, which is wrong, instead of their original filenames like PXL_20231003_125152999.jpg

Videos: Video's names are named like photos, the date of upload. Some video info is not shown.

photos

@mikebilly mikebilly added the bug Something isn't working label Oct 23, 2023
@mikebilly mikebilly changed the title Not displaying full EXIF information Not displaying full EXIF information + Showing date of upload as filename. Oct 23, 2023
@mikebilly
Copy link
Author

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)

@mikebilly mikebilly reopened this Oct 23, 2023
@mikebilly
Copy link
Author

@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.

@pacoorozco
Copy link
Collaborator

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
Copy link
Collaborator

pacoorozco commented Oct 24, 2023

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.

@pacoorozco pacoorozco changed the title Not displaying full EXIF information + Showing date of upload as filename. Uploads are showing date of upload as filename. Oct 24, 2023
@pacoorozco pacoorozco added the WIP label Oct 24, 2023
@mikebilly
Copy link
Author

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.

pacoorozco added a commit that referenced this issue Oct 24, 2023
Signed-off-by: pacoorozco <paco@pacoorozco.info>
@pacoorozco pacoorozco added fixed The bug has been fixed, but the fix is not permanent. Needs a refactor. and removed WIP labels Oct 24, 2023
pacoorozco added a commit that referenced this issue Oct 24, 2023
Fix #398: Uploads are showing date of upload as filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed The bug has been fixed, but the fix is not permanent. Needs a refactor.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants