Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Allow more mime types to be uploaded #95

Open
mirisbowring opened this issue Jun 16, 2023 · 3 comments
Open

Allow more mime types to be uploaded #95

mirisbowring opened this issue Jun 16, 2023 · 3 comments

Comments

@mirisbowring
Copy link

Since immich-app/immich#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:

CLI/bin/index.ts

Lines 25 to 48 in 5b5b325

const SUPPORTED_MIME = [
// IMAGES
'image/heif',
'image/heic',
'image/jpeg',
'image/png',
'image/jpg',
'image/gif',
'image/heic',
'image/heif',
'image/dng',
'image/x-adobe-dng',
'image/webp',
'image/tiff',
'image/nef',
'image/x-nikon-nef',
// VIDEO
'video/mp4',
'video/webm',
'video/quicktime',
'video/x-msvideo',
'video/3gpp',
];

@uhthomas
Copy link
Member

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();
 }

@mirisbowring
Copy link
Author

mirisbowring commented Jun 17, 2023

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 immich-app/immich#2824 😀

@uhthomas
Copy link
Member

See immich-app/immich#2824

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants