Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

Is it possible with a Stored Procedure to upload a file?

I want to replace this by a Stored Procedure function:

curl -X 'POST' \ 'https://dev.somesite/api-external/stock/import-file' \

-H 'accept: application/json' \

-H 'authorization: Basic dHN....==' \

-H 'Content-Type: multipart/form-data' \

-F 'File=@myfile.csv;type=application/'

My Stored Procedure:

ALTER PROCEDURE "DBA"."sp_tsd_catalogus_toc"(IN "file" NTEXT)

result( "Attribute" long NVARCHAR,"Values" long NVARCHAR, instance INTEGER )

url ''

type 'HTTP:POST'

header 'accept:application/json\nauthorization: Basic dHNk...==\ncontent-Type:multipart/form-data'

With this I got a 400 error. I think because the in parameter 'file' contains the content of the file. Is it possible to save a file at the serverside and post that filename in de SP?

Anybody an idea?

Tia Hans

asked 24 Mar '22, 06:42

HansTSD's gravatar image

accept rate: 20%

edited 24 Mar '22, 06:49

I would generally use the "web client debug feature" (aka the -zoc database server option or via "CALL sa_server_option('WebClientLogging', 'On')") to check the request sent to the web server.

(25 Mar '22, 11:15) Volker Barth

We upload documents in the database

CREATE SERVICE rawUploadDocument
TYPE 'raw' 
CALL UploadDocument(HTTP_BODY())

In this procedure in the end we store the file on disc

 set l_FullFilename = 'c:\images\word\'\|| Description ||'.'|| Extension
 select xp_write_file(l_FullFilename,BASE64_DECODE(Image))

We use Json to send the image base 64 encoded

{"extension": "docx"
 "Description": "Quote for customer xxxxxx"
 "Image": "....." -- Image Base64 encoded

I hope this wil help

permanent link

answered 25 Mar '22, 05:36

Frank%20Vestjens's gravatar image

Frank Vestjens
accept rate: 21%

I asked the API developer to modify there API to accept the content of the file, instead of a file upload. So the problem is 'solved', I can upload my data with SA17 now.

permanent link

answered 28 Mar '22, 02:33

HansTSD's gravatar image

accept rate: 20%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 24 Mar '22, 06:42

question was seen: 1,040 times

last updated: 28 Mar '22, 02:33