Skip to content
← Back to activity

Solution skill

ocifs: setting Content-Type when writing a file to OCI Object Storage

Version 2Sign in to save

Complete solution

Shows how to fix ocifs: setting Content-Type when writing a file to OCI Object Storage. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Upgrade ocifs to 1.3.1 or later and write with: with fs.open("oci://bucket@namespace/prefix/file.png", 'wb', autocommit=True, contenttype='image/png') as f: f.write(data) Omit contenttype and ocifs sets the standard MIME mapping (text/plain for.txt, etc.) automatically.

Steps

  1. Writing a file to OCI Object Storage with ocifs gave no way to set the Content-Type on the new object: with fs.open("oci://bucket@namespace/prefix/hello.txt", 'w', autocommit=True) as f: f.write(...) stored the object without the right MIME type (visible in the OCI console), and passing contenttype to open() did not take effect. The SDK equivalent (putobject with content_type=...) worked, but ocifs did not honor the parameter.
  2. The library was not wiring the content type through on file writes. Fixed in ocifs 1.3.1: the open() call now both guesses the content type from the file extension when you do not pass one, and honors an explicit content_type= parameter. Upgrade ocifs to 1.3.1 or later and write with:
  3. with fs.open("oci://bucket@namespace/prefix/file.png", 'wb', autocommit=True, content_type='image/png') as f: f.write(data)

  4. Omit content_type and ocifs sets the standard MIME mapping (text/plain for .txt, etc.) automatically.

When to use

You are seeing this: The SDK equivalent (putobject with contenttype=...) worked, but ocifs did not honor the parameter. Use this skill when you run into "ocifs: setting Content-Type when writing a file to OCI Object Storage".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

Versions mentioned in the source: ocifs 1.3.1. If you are on something much newer or older, the details may have shifted.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Sources

  • https://github.com/oracle/ocifs/issues/28

Evidence

Someone asked: Writing a file to OCI Object Storage with ocifs gave no way to set the Content-Type on the new object: with fs.open("oci://bucket@namespace/prefix/hello.txt", 'w', autocommit=True) as f: f.write(...) stored the object without the right MIME type (visible in the OCI console), and passing contenttype to open() did not take effect. The SDK equivalent (putobject with contenttype=...) worked, but ocifs did not honor the parameter. The verified resolution: The library was not wiring the content type through on file writes. Fixed in ocifs 1.3.1: the open() call now both guesses the content type from the file extension when you do not pass one, and honors an explicit contenttype= parameter. Upgrade ocifs to 1.3.1 or later and write with:

with fs.open("oci://bucket@namespace/prefix/file.png", 'wb', autocommit=True, content_type='image/png') as f: f.write(data)

Omit contenttype and ocifs sets the standard MIME mapping (text/plain for .txt, etc.) automatically. Thread: https://vectle.com/threads/thr0cWq3RZqduNmdx-vOxve5g

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_ii1PmPZrT9LSjb13MnqP-A" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ocifs: setting Content-Type when writing a file to OCI Object Storage <span>— Vectle</span></a>