1

I need help with the code below. I am running it through a Windows app that executes the script within itself. It works fine for files up to 149 MB. After it errors out with

Provider: Not enough storage is available to complete this operation.

I have tried researching this but found no suitable answers so far. Does anyone have any ideas on how to overcome this error or is this a Windows environment limitation? If so, is there a way to go around? I need to be able to upload up to 3GB file size.

Code:

Option Explicit

' Declare variables
Dim request, HTTPPost, oHTTP, postURL, inStream, bytData, bytPayLoad
Dim inFile, AccessToken, strBoundary, jobID, tFLOW_JSON
Const TypeBinary = 1
Const ForReading = 1, ForWriting = 2, ForAppending = 8

' Setup variable
AccessToken = "abgdket567jjjhd8kk"
jobID = "16788"
tFLOW_JOSN = "First_Upload"
inFile = "D:\e_Brain\AUTOMATION\tFLOW\API\ORDER\CREATED\FILE_IN\" + jobID + ".pdf"
strBoundary = "------WebKitFormBoundary7MA4YWxkTrZu0gW"

' Read Incoming File as Binary
With CreateObject("ADODB.Stream")
    .Type = 1
    .Mode = 3
    .Open
    .LoadFromFile inFile
    bytData = .Read '->This is where it errors out
End With

' Setup BODY data
With CreateObject("ADODB.Stream")
    .Mode = 3
    .Charset = "Windows-1252"
    .Open
    .Type = 2
    .WriteText "--" & strBoundary & vbCrLf
    .WriteText "Content-Disposition: form-data; name=""artwork""; filename=""" & inFile & """" & vbCrLf
    .WriteText "Content-Type: application/pdf" & vbCrLf & vbCrLf
    .Position = 0
    .Type = 1
    .Position = .Size
    .Write bytData
    .Position = 0
    .Type = 2
    .Position = .Size
    .WriteText vbCrLf & "--" & strBoundary & "--"
    .Position = 0
    .Type = 1
    bytPayLoad = .Read
End With

' POST FILE
postURL = "https://linemark.tflowproof.com/api/v2/job/" + jobID + "/executeTransition?_json={""transition_name"":""" + tFLOW_JSON + """}"

With CreateObject("MSXML2.ServerXMLHTTP")
    .SetTimeouts 0, 60000, 300000, 300000
    .Open "POST", postURL, False
    .SetRequestHeader "Content-type", "multipart/form-data; boundary=" & strBoundary
    .SetRequestHeader "Authorization", "" + AccessToken + ""
    .Send bytPayLoad
End With
Alberto G
  • 19
  • 3
  • 1
    Welcome to StackOverflow! Please take a look at the markdowns and [edit] your question, this is just a mess. – Hille Jan 22 '19 at 15:19
  • [Maybe related](https://stackoverflow.com/q/6626056/1630171). – Ansgar Wiechers Jan 22 '19 at 19:14
  • Server has 64GB Memory and 1TB SSD with 900MB space available. So no problems with memory size nor HDD space. – Alberto G Jan 22 '19 at 20:32
  • Please read the other answers to that question as well. – Ansgar Wiechers Jan 22 '19 at 22:04
  • I read and did some of the things that it said and still on the same boat Ansgar Wiechers... I have no idea of what else to do. – Alberto G Jan 22 '19 at 22:43
  • It errors because you try to read the file in one large chunk rather than read/write a set amount each time breaking the process into managable size chunks *(also referred to as the buffer)*. The duplicate question already has a great [answer write up by MC-ND](https://stackoverflow.com/a/41241229/692942) on the correct approach to take. – user692942 Jan 22 '19 at 23:16
  • 1
    @Lankymart - In my case I am not converting it to B64... I want to keep it binary...You have the b64 object setup to be "bin.base64". What will the correct code to buffer it in binary? Thanks. – Alberto G Jan 23 '19 at 14:13
  • @AlbertoG It has nothing to do with base64 encoding, that was just the example problem the OP wanted to solve. The issue is trying to read a large file into a stream in one chunk, that is were the buffer solution provided in the answer solved the initial problem. Actually try reading the answer through, its full of useful information about handling large file read/write operations using `ADODB.Stream`. – user692942 Jan 24 '19 at 18:38
  • Thanks everyone, but it seems to be a bigger problem that it is worth with Windows. I was able to go by the `ADODB.Stream` but started having the same issue at the `.Send`. I am changing to Linux and PHP. – Alberto G Jan 25 '19 at 19:33

0 Answers0