radix
radix
Explore posts from servers
CDCloudflare Developers
Created by alex35mil on 11/30/2023 in #🦀rust-on-workers
How to send `FormData` via `Fetch`? I
let api_url =
format!("https://api.cloudflare.com/client/v4/accounts/{}/images/v1", self.account_id);
let metadata = serde_json::to_string(&json!({"purpose": purpose.to_string()}))?;
let form = reqwest::multipart::Form::new()
.text("metadata", metadata)
.text("id", self.gen_custom_id())
.text("url", url.to_owned());
let client = reqwest::Client::new();
let response = client
.post(api_url)
.multipart(form)
.header("Authorization", format!("Bearer {}", &self.images_token))
.send()
.await?;
let response = response.error_for_status()?;
let api_url =
format!("https://api.cloudflare.com/client/v4/accounts/{}/images/v1", self.account_id);
let metadata = serde_json::to_string(&json!({"purpose": purpose.to_string()}))?;
let form = reqwest::multipart::Form::new()
.text("metadata", metadata)
.text("id", self.gen_custom_id())
.text("url", url.to_owned());
let client = reqwest::Client::new();
let response = client
.post(api_url)
.multipart(form)
.header("Authorization", format!("Bearer {}", &self.images_token))
.send()
.await?;
let response = response.error_for_status()?;
6 replies
CDCloudflare Developers
Created by alex35mil on 11/30/2023 in #🦀rust-on-workers
How to send `FormData` via `Fetch`? I
e.g., this is how I interact with the CloudFlare "images" API, which also uses form data:
6 replies
CDCloudflare Developers
Created by alex35mil on 11/30/2023 in #🦀rust-on-workers
How to send `FormData` via `Fetch`? I
FWIW, you can also use reqwest which has a nicer API than the workers-provided Fetch
6 replies
CDCloudflare Developers
Created by radix on 11/27/2023 in #workers-help
Is it possible to run a different build command based on whether you're doing `wrangler dev/deploy`
Unfortunately, I haven't been able to figure out a way to do something conditional automatically based on whether dev or deploy is being run, but I solved this by just implementing a custom command that checks my own custom environment variable and I only set that variable when I'm running wrangler dev, e.g. WORKER_MODE="--dev" wrangler dev
2 replies