Skip to content

Instantly share code, notes, and snippets.

Created December 7, 2020 01:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Uploading Image Files to Google Photos using axios

Uploading Image Files to Google Photos using axios

This is a sample script for uploading the image files to the specific album in Google Photos using axios.

Before you use this script, please retrieve the access token for uploading the files using Google Photos API.

Sample script

In this sample script, several image files can be uploaded.

<input type="file" id="files" name="file" multiple />
<input type="button" onclick="main()" value="upload" />

  function upload({ files, albumId, accessToken }) {
    const description = new Date().toISOString();
    const promises = Array.from(files).map((file) => {
      return new Promise((r) => {
          .post("", file, {
            headers: {
              "Content-Type": "application/octet-stream",
              "X-Goog-Upload-Protocol": "raw",
              Authorization: `Bearer ${accessToken}`,
          .then(({ data }) => {
              description: description,
              simpleMediaItem: { fileName:, uploadToken: data },
    return Promise.all(promises).then((e) => {
      return new Promise((resolve, reject) => {
            JSON.stringify({ albumId: albumId, newMediaItems: e }),
              headers: {
                "Content-type": "application/json",
                Authorization: `Bearer ${accessToken}`,

  // This function is run.
  function main() {
    const obj = {
      files: document.getElementById("files").files,
      albumId: "###", // Please set the album ID.
      accessToken: "###", // Please set your access token.
      .then((e) => console.log(e))
      .catch((err) => console.log(err));


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment