{"record":{"id":"b4f9ef03f43bbc71","repo":"LykosAI/StabilityMatrix","slug":"unable-to-get-preview-image-file-extension-from-from-uri-and","errorCode":null,"errorMessage":"Unable to get preview image file extension from from Uri, and no file extension provided","messagePattern":"Unable to get preview image file extension from from Uri, and no file extension provided","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Avalonia/Services/ModelImportService.cs","lineNumber":334,"sourceCode":"        // fetching the preview in the background.\n        var cleanupFilePaths = new List<string>();\n        if (connectedModelInfo is not null)\n        {\n            await connectedModelInfo.SaveJsonToDirectory(downloadFolder, modelBaseFileName);\n            cleanupFilePaths.Add(\n                downloadFolder.JoinFile(modelBaseFileName + ConnectedModelInfo.FileExtension)\n            );\n        }\n\n        FilePath? previewImageDownloadPath = null;\n        if (previewImageUri is not null)\n        {\n            if (previewImageFileExtension is null)\n            {\n                previewImageFileExtension = Path.GetExtension(previewImageUri.LocalPath);\n                if (string.IsNullOrEmpty(previewImageFileExtension))\n                {\n                    throw new InvalidOperationException(\n                        \"Unable to get preview image file extension from from Uri, and no file extension provided\"\n                    );\n                }\n            }\n\n            previewImageDownloadPath = downloadFolder.JoinFile(\n                modelBaseFileName + \".preview\" + previewImageFileExtension\n            );\n\n            cleanupFilePaths.Add(previewImageDownloadPath);\n        }\n\n        // Create tracked download\n        // todo: support multiple uris\n        var modelUri = modelUris.First();\n        var download = trackedDownloadService.NewDownload(modelUri, downloadPath);\n\n        // Add hash info","sourceCodeStart":316,"sourceCodeEnd":352,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/Services/ModelImportService.cs#L316-L352","documentation":"DoCustomImport throws this InvalidOperationException when it needs to download a preview image but cannot determine the file extension: the URI's local path has no extension and the caller did not supply previewImageFileExtension. The service requires an extension to build the destination file path.","triggerScenarios":"Importing a model whose preview image URL has no extension (e.g. signed/blob URLs like ...?token=x or /preview/12345) without passing previewImageFileExtension.","commonSituations":"Civitai or CDN preview URLs behind redirects that hide extensions; blob-storage URLs with query parameters only; custom preview image links without a file suffix; programmatic imports omitting the optional extension parameter.","solutions":["Pass previewImageFileExtension explicitly (e.g. \".jpeg\") when the preview URL lacks one","Inspect the HTTP Content-Type header of the preview URL and derive the extension from it","Use a preview URL that includes a real file extension if you control the source","Default to the known image type (e.g. .jpg for Civitai image endpoints) when constructing the import call"],"exampleFix":"// before\nawait importService.DoCustomImport(downloadUri, \"model.safetensors\", localModelFile, modelDbModel, previewImageUri: blobUri);\n// after\nawait importService.DoCustomImport(downloadUri, \"model.safetensors\", localModelFile, modelDbModel,\n    previewImageUri: blobUri,\n    previewImageFileExtension: \".jpeg\"); // explicit, since blobUri has no extension","handlingStrategy":"try-catch","validationCode":"var ext = previewImageFileExtension ?? Path.GetExtension(previewImageUri.LocalPath);\nif (string.IsNullOrEmpty(ext))\n    ext = \".jpeg\"; // or derive from Content-Type via a HEAD request","typeGuard":"bool HasPreviewExtension(Uri uri) => !string.IsNullOrEmpty(Path.GetExtension(uri.LocalPath));","tryCatchPattern":"try\n{\n    await importService.DoCustomImport(...);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"preview image file extension\"))\n{\n    // retry with an explicit previewImageFileExtension\n}","preventionTips":["Always supply previewImageFileExtension for extension-less/blob URLs","Derive extension from Content-Type for unknown sources","Prefer preview URLs with real file suffixes"],"tags":["import","preview-image","extension","url"],"backgroundTag":"invalid-url-format","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}