import * as wmill from "windmill-client"
import { S3Object } from "windmill-client"
/**
* Upload Attachment
* Attach a file from Windmill object storage to a task, project or project brief (max 100 MB). The file keeps the name at the end of its storage path unless `name` is set.
*/
export async function main(
auth: RT.Asana,
parent: string,
file: S3Object,
name: string | undefined
) {
const bytes = await wmill.loadS3File(file)
if (!bytes) {
throw new Error(`Could not load ${file.s3} from object storage`)
}
const form = new FormData()
form.append("parent", parent)
form.append("file", new Blob([bytes]), name || file.s3.split("/").pop())
const response = await fetch("https://app.asana.com/api/1.0/attachments", {
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
body: form,
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 3 hours ago