bb-plane-fork/apps/api/plane/utils
binarybeach 9fb1ad44cd binarybeachio: presigned PUT for uploads (R2/B2 don't implement PostObject)
== WHY (KEEP THIS — IT'S WHY THE FORK EXISTS) ==

Vanilla Plane's upload flow uses AWS S3 PostObject (presigned POST +
multipart/form-data + signed-policy-document). Cloudflare R2 AND
Backblaze B2 — the two most common self-host S3-compatible backends —
both return HTTP 501 NotImplemented for PostObject. Empirically verified
2026-04-30 against B2 s3.us-west-004.backblazeb2.com from inside Plane's
own prod api container, replicating Plane's exact boto3 call:

  PUT against B2:  200 OK
  POST against B2: 501 NotImplemented "This API call is not supported."
  POST against R2: 501 NotImplemented (failure that started this thread)

The error code is `NotImplemented` (not `SignatureDoesNotMatch` etc),
meaning the server rejects the verb itself — no boto3 config, addressing-
style flag, or signature variant fixes it. Tested both path-style and
virtual-hosted-style URLs against B2; both fail identically for POST.

This patch rewrites the upload flow to use presigned PUT, which is
universally supported (R2, B2, AWS S3 native, MinIO, Wasabi, etc).

== WHAT (FIVE-FILE BACKEND, FIVE-FILE FRONTEND) ==

Backend:
* apps/api/plane/settings/storage.py — S3Storage.generate_presigned_post
  now mints a presigned PUT URL via generate_presigned_url(HttpMethod="PUT").
  Method name kept for caller compat. Response shape:
  {url, method: "PUT", fields: {Content-Type, key}}.
* apps/api/plane/utils/openapi/responses.py — example response updated.
* apps/api/plane/tests/unit/settings/test_storage.py — 2 tests updated to
  assert the new boto3 call.

Frontend:
* packages/types/src/file.ts — TFileSignedURLResponse.upload_data adds
  optional method?: "PUT" | "POST"; drops AWS POST-form-data fields.
* packages/services/src/file/helper.ts — generateFileUploadPayload now
  returns a TFileUploadRequest descriptor (url+method+body+headers) that
  dispatches on method. POST branch kept for upstream parity but the
  fork backend never emits POST.
* packages/services/src/file/file-upload.service.ts +
  apps/web/core/services/file-upload.service.ts — uploadFile signature
  changes from (url, FormData, progress?) to (payload, progress?).
* 5 caller sites updated (apps/web/core/services/file.service.ts x3,
  issue_attachment.service.ts x1, sites-file.service.ts x1).

== TRADEOFFS ACCEPTED ==

* Lost: signed `content-length-range` enforcement at the storage layer.
  Server-side validation in the API view still rejects oversized requests
  with 413 before minting the URL, so a determined client could only
  over-upload by misreporting size, capped at the bucket's own size limit.
* Different request shape on the wire (PUT with raw binary body vs POST
  with multipart form). Externally invisible to users.

== ROLLBACK ==

If this becomes a maintenance nightmare:

  git revert <this-commit-sha>
  # rebuild + push images, swap compose tags, redeploy

After revert, uploads will only work against backends that implement
PostObject (MinIO, AWS S3 native). R2 and B2 will return 501 again.

== FULL DECISION RECORD ==

binarybeachio repo: docs/features/storage-upload-flow.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 17:56:52 -10:00
..
core chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
exporters [SECUR-105] fix: csv injection vulnerability sanitization #8611 2026-02-13 15:37:13 +05:30
filters chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
instance_config_variables chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
openapi binarybeachio: presigned PUT for uploads (R2/B2 don't implement PostObject) 2026-04-30 17:56:52 -10:00
permissions chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
porters [SECUR-105] fix: csv injection vulnerability sanitization #8611 2026-02-13 15:37:13 +05:30
__init__.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
analytics_events.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
analytics_plot.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
build_chart.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
cache.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
color.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
constants.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
content_validator.py refactor: table drag preview using decorations (#8597) 2026-02-13 17:59:37 +05:30
csv_utils.py chore: admin folder structure (#8632) 2026-02-13 16:29:45 +05:30
cycle_transfer_issues.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
date_utils.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
email.py [WEB-5917] fix: generate clean plain text from HTML email template #8535 2026-02-17 00:44:52 +05:30
error_codes.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
exception_logger.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
global_paginator.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
grouper.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
host.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
html_processor.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
imports.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
ip_address.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
issue_filters.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
issue_relation_mapper.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
issue_search.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
logging.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
markdown.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
order_queryset.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
paginator.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
path_validator.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
telemetry.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
timezone_converter.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
url.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30
uuid.py chore: add copyright (#8584) 2026-01-27 13:54:22 +05:30