CLI icon indicating copy to clipboard operation
CLI copied to clipboard

Allow more mime types to be uploaded

Open mirisbowring opened this issue 1 year ago • 3 comments

Since https://github.com/immich-app/immich/issues/2156 is implemented and released now, it would be great to allow RAW files for the cli uploader.

Tried today and it seems like it is not listed in here: https://github.com/immich-app/CLI/blob/5b5b325844169ca3681a78112b962beb864ca891/bin/index.ts#L25-L48

mirisbowring avatar Jun 16 '23 16:06 mirisbowring

I agree, though it's actually a lot more complicated than it should be. I wrote this hack so I could upload my .ARW files :)

❯ git diff
diff --git a/bin/index.ts b/bin/index.ts
index ac58de4..c84412b 100644
--- a/bin/index.ts
+++ b/bin/index.ts
@@ -38,6 +38,7 @@ const SUPPORTED_MIME = [
   'image/tiff',
   'image/nef',
   'image/x-nikon-nef',
+  'image/x-sony-arw',

   // VIDEO
   'video/mp4',
@@ -179,12 +180,13 @@ async function upload(
   const uniqueFiles = new Set(files);

   for (const filePath of uniqueFiles) {
-    const mimeType = mime.lookup(filePath) as string;
+    const mimeType = filePath.toLowerCase().endsWith('arw') ? 'image/x-sony-arw' : mime.lookup(filePath) as string;
     if (SUPPORTED_MIME.includes(mimeType)) {
       try {
         const fileStat = fs.statSync(filePath);
         localAssets.push({
           id: `${path.basename(filePath)}-${fileStat.size}`.replace(/\s+/g, ''),
+          mimeType,
           filePath,
         });
       } catch (e) {
@@ -385,7 +387,7 @@ async function startUpload(endpoint: string, key: string, asset: any, deviceId:
     data.append('fileExtension', path.extname(asset.filePath));
     data.append('duration', '0:00:00.000000');

-    data.append('assetData', fs.createReadStream(asset.filePath));
+    data.append('assetData', fs.createReadStream(asset.filePath), { contentType: asset.mimeType });

     try {
       await fs.promises.access(`${asset.filePath}.xmp`, fs.constants.W_OK);
@@ -499,7 +501,7 @@ async function validateConnection(endpoint: string, key: string) {
 }

 function getAssetType(filePath: string) {
-  const mimeType = mime.lookup(filePath) as string;
+  const mimeType = filePath.toLowerCase().endsWith('.arw') ? 'image/x-sony-arw' : mime.lookup(filePath) as string;

   return mimeType.split('/')[0].toUpperCase();
 }

uhthomas avatar Jun 17 '23 00:06 uhthomas

Wow, i was thinking that just adding RAW to the array would be sufficient 😅

Probably, for the future this cli client should import the servers library for file processing to prevent this doubled maintenance overhead? 🤔

EDIT: Just saw https://github.com/immich-app/immich/issues/2824 😀

mirisbowring avatar Jun 17 '23 03:06 mirisbowring

See https://github.com/immich-app/immich/issues/2824

uhthomas avatar Jun 17 '23 03:06 uhthomas