ms access - Uploading a file to Azure Blob Storage using VBA and MS XMLHTTP -


i've been trying upload file azure storage using vba in microsoft access far without success.

i have had search around , have found code looks promising can't work. seems many others have been looking similar solution or working azure vba.

this code;

private function pvpostfile(surl string, sfilename string, optional byval basync boolean) string const str_boundary  string = "3fbd04f5-b1ed-4060-99b9-fca7ff59c113" dim nfile           integer dim babuffer()      byte dim spostdata       string  '--- read file nfile = freefile open sfilename binary access read nfile if lof(nfile) > 0     redim babuffer(0 lof(nfile) - 1) byte     nfile, , babuffer     spostdata = strconv(babuffer, vbunicode) end if close nfile '--- prepare body spostdata = "--" & str_boundary & vbcrlf & _     "content-disposition: form-data; name=""uploadfile""; filename=""" & mid$(sfilename, instrrev(sfilename, "\") + 1) & """" & vbcrlf & _     "content-type: application/octet-stream" & vbcrlf & vbcrlf & _     spostdata & vbcrlf & _     "--" & str_boundary & "--" '--- post createobject("microsoft.xmlhttp")     .open "post", surl, basync     .setrequestheader "content-type", "multipart/form-data; boundary=" & str_boundary     .send pvtobytearray(spostdata)     if not basync         pvpostfile = .responsetext     end if end end sub  private function pvtobytearray(stext string) byte()     pvtobytearray = strconv(stext, vbfromunicode) end function 

(thanks - https://wqweto.wordpress.com/2011/07/12/vb6-using-wininet-to-post-binary-file/)

when try code using azure storage url in form

https://xxxxx.blob.core.windows.net/  

and filename (c:\temp\test.txt) following error;

<?xml version="1.0" encoding="utf-8"?><error><code>unsupportedhttpverb</code><message>the resource doesn't support specified http verb. 

i suspect there's problem in header or post data rather vba , not area.

any appreciated.

i came across post i'm searching same answer uploading images azure blob storage. took me 2 days answer. , code posted above did me partly solve problem.

i post solution here in case else looking same answer.

before can use code below, need shared access signature (sas) azure portal (manage panel). should able google answers on this.

public sub uploadafile(surl string, sfilename string)     dim adostream object     set adostream = createobject("adodb.stream")     adostream.mode = 3          ' read write     adostream.type = 1          ' adtypebinary     adostream.open     adostream.loadfromfile (sfilename)     createobject("microsoft.xmlhttp")         adostream.position = 0         .open "put", surl, false         .setrequestheader "content-length", "0" 'this not must         .setrequestheader "x-ms-blob-type", "blockblob"         .send adostream.read(adostream.size)     end     set adostream = nothing end sub 

surl url looks (i'm in china host different): https://myaccount.blob.core.chinacloudapi.cn/products/newimagename.jpg?sv=2016-05-31&ss=bfpq&srt=dco&sp=rydlscup&se=2017-07-30t18:40:26z&st=2017-07-28t10:40:26z&spr=https&sig=mjgdyecayitp0ivvrd4oug%2bz%2chn7wpo2nntcn0pyrcu%4d

the 1 bolded sas token generated azure.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -