Hello everyone.
I want to upload multiple documents using a Powsershell script via API.
As a first step, I try to upload a single document, but I always get “bad request” (400) as an error message.
I already gone through the references, unfortunately without success.
$api_token ="01234012301234"
$server = "https/ser.com/api/v2.1/dtable"
$headers=@{}
$headers.Add("accept", "application/json")
$headers.Add("content-type", "application/json")
$headers.Add("authorization", "Bearer $api_token")
$response = Invoke-WebRequest -Uri $server'/app-upload-link/' -Method GET -Headers $headers|ConvertFrom-Json
$uploadUrl = $response.upload_link
$parentDir = $response.parent_path
$relPath = $response.file_relative_path
$replace = "0"
$output = Invoke-WebRequest -Uri $uploadUrl'?ret-json=1' -Method POST -Headers $headers -ContentType 'multipart/form-data; boundary=---011000010111000001101001' -Body '-----011000010111000001101001
Content-Disposition: form-data; name="file"
data:text/plain;name=test.txt;base64,VGVzdCBtZSEhIQ==
-----011000010111000001101001
Content-Disposition: form-data; name="parent_dir"
$parentDir
-----011000010111000001101001
Content-Disposition: form-data; name="replace"
$replace
-----011000010111000001101001
Content-Disposition: form-data; name="relative_path"
$relPath
-----011000010111000001101001--
'
Maybe someone can help me solving the issue.
Thank you.
cdb
February 22, 2024, 9:57am
2
I am not familiar with powershell, but I think you use the API in the wrong way:
This is what you get from /app-upload-link/
{
"upload_link": "https://cloud.seafile.com/seafhttp/upload-api/83e701c8-84ba-498c-91b1-ddb3789edb7e",
"parent_path": "/asset/a275d870-fd55-48e4-8c4a-5fd6f2549765",
"img_relative_path": "images/2021-08",
"file_relative_path": "files/2021-08"
}
You can not just use $response.upload_link
. The api request to upload a file only requires the part after the upload-api. Please read the api documentation again.
Thank you for the answer, but I think this wont help me.
According to Seatable Reference Upload-File-Image the Invoke-WebRequest expect the full link with the upload_link.
$headers=@{}
$headers.Add("accept", "application/json")
$headers.Add("content-type", "multipart/form-data")
$response = Invoke-WebRequest -Uri 'https://cloud.seatable.io/seafhttp/upload-api/11111111-111111-111111?ret-json=1' -Method POST -Headers $headers
The exception handling contains follwing content:
IsMutuallyAuthenticated : False
Cookies : {}
Headers : {Connection, Content-Length, Content-Type, Date...}
SupportsHeaders : True
ContentLength : 26
ContentEncoding :
ContentType : application/json; charset=utf-8
CharacterSet : utf-8
Server : nginx/1.24.0
LastModified : 23.02.2024 10:10:16
StatusCode : BadRequest
StatusDescription : Bad Request
ProtocolVersion : 1.1
ResponseUri : https://myserver.com/seafhttp/upload-api/ehc2db13-55fe-5011-a777-b17d49c369d8?ret-json=1
Method : POST
IsFromCache : False
Unfortunately I haven’t come to a solution yet.
cdb
February 23, 2024, 10:20am
4
I can guarantee you that the API endpoint is working as described on api.seatable.io .
system
Closed
February 28, 2024, 2:11am
5
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.