Skip to content

Preserve blob content-type on save in BlobContainerFS#1505

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-blob-storage-content-type
Draft

Preserve blob content-type on save in BlobContainerFS#1505
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-blob-storage-content-type

Conversation

Copilot AI commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Saving a blob file via VS Code overwrote the existing content-type with a value derived from the file extension (e.g. application/javascript; charset=UTF-8application/javascript), discarding charset and other parameters.

Changes

  • src/BlobContainerFS.tswriteFile: Replaced the separate blobClient.exists() call with blobClient.getProperties(), which both checks existence (via 404 catch) and retrieves the current content-type in a single round-trip. The existing content-type is then forwarded on upload; mime.getType() is only used as a fallback for new blobs.
// Before: always derived content-type from file extension
await blobClient.getBlockBlobClient().uploadData(content, {
    blobHTTPHeaders: {
        blobContentType: mime.getType(uri.path) || undefined
    }
});

// After: preserve existing content-type; fall back to mime detection for new blobs
let existingProperties: BlobGetPropertiesResponse | undefined;
try {
    existingProperties = await blobClient.getProperties();
} catch (error) {
    if (parseError(error).errorType !== "404") { throw error; }
}

await blobClient.getBlockBlobClient().uploadData(content, {
    blobHTTPHeaders: {
        blobContentType: existingProperties?.contentType || mime.getType(uri.path) || undefined
    }
});

This matches the existing pattern in blobUtils.ts (getExistingProperties / createOrUpdateBlockBlob) already used by the AzureStorageFS code path.

Copilot AI and others added 2 commits April 29, 2026 18:26
…nce check and content-type preservation

Agent-Logs-Url: https://github.com/microsoft/vscode-azurestorage/sessions/8b6a080a-42cc-49b2-a1a8-49e8bb86ecd8

Co-authored-by: MicroFish91 <40250218+MicroFish91@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix content-type change when editing files in blob storage Preserve blob content-type on save in BlobContainerFS Apr 29, 2026
Copilot AI requested a review from MicroFish91 April 29, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using vs-code to edit files in blob storage changes the files content-type.

2 participants