Created
March 6, 2025 06:38
-
-
Save donma/ddae6cce8bd55d47975a352ba8af6d42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var filePath = AppDomain.CurrentDomain.BaseDirectory + "oooo.jpg"; | |
UploadImageToIPFS(filePath); | |
static void UploadImageToIPFS(string filePath) | |
{ | |
var client = new RestClient("https://app.img2ipfs.org/api/v0/add"); | |
var request = new RestRequest("", Method.Post); | |
//不要手動設置 Content-Type,讓 RestSharp 自動處理 multipart | |
request.AddHeader("accept", "application/json, text/javascript, */*; q=0.01"); | |
request.AddHeader("origin", "https://cdn.ipfsscan.io"); | |
request.AddHeader("referer", "https://cdn.ipfsscan.io/"); | |
request.AddHeader("sec-fetch-mode", "cors"); | |
request.AddHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0"); | |
// 使用 AddFile 讓 RestSharp 自動處理 boundary | |
request.AddFile("file", filePath, "image/jpeg"); | |
// 發送請求 | |
var response = client.Execute(request); | |
Console.WriteLine(response.Content); // 印出 API 回應 | |
} | |
//Result | |
/* | |
{"Name":"oooo.jpg","Hash":"Qmb17UZj1FH4DchcJcfqAtMn4Qn2z5TLkm1dcCrT8GATGh","Size":"5009", | |
"Url":"https://cdn.img2ipfs.com/ipfs/Qmb17UZj1FH4DchcJcfqAtMn4Qn2z5TLkm1dcCrT8GATGh?filename=oooo.jpg"} | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment