ImmichI
Immich12mo ago
Sonorc

API - Upload a picture - uploadAsset

Hello, the current uploadAsset doesn't work? I want to upload an image via node js and I always get an error message.

I feel like I have recreated and tested the API key 100 times. (/user-settings -> API key)

https://immich.app/docs/api/upload-asset/

  const axios = require('axios');
  const FormData = require('form-data');
  const fs = require('fs');
  let data = new FormData();

  data.append('assetData', fs.createReadStream('H:\\Git\\bilder\\Neu\\backend\\uploads\\1351335.png'));
  data.append('deviceAssetId', 'assetTest');
  data.append('deviceId', 'deviceTest');
  data.append('fileCreatedAt', '2024-12-27T11:02:39');
  data.append('fileModifiedAt', '2024-12-27T11:02:39');
  
  
  let config = {
    method: 'post',
    maxBodyLength: Infinity,
    url: 'http://127.0.0.1:8980/api/assets?key=z8vuYdyn3loVPP8DhBx6S0Zh2aKiU3T8CzVoT7jDZIs',
    headers: { 
      'Content-Type': 'multipart/form-data', 
      'Accept': 'application/json', 
      ...data.getHeaders()
    },
    data : data
  };
  
  
  axios.request(config)
  .then((response) => {
    console.log(JSON.stringify(response.data));
  })
  .catch((error) => {
    console.log(error);
  });

data: {
message: 'Invalid share key',
error: 'Unauthorized',
statusCode: 401,
correlationId: '0ikytt67'
}
Was this page helpful?