title: Uploading binary files to a REST API via VBA
body: <p>I am in the process of using VBA in SolidWorks' to integrate Autodesk's PLM 360 into SolidWorks. The problem is that I have very little experience interacting with REST APIs, and it seems like uploading files to a cloud application is probably the most complicated part of that. In any case, it is very important for me to be able to do two things with VBA from SolidWorks: (1) add images to an item's description (<a href="http://help.autodesk.com/view/PLM/ENU/?guid=GUID-89834BD4-BCC9-4124-BE6C-B307875DE84A" rel="nofollow">documentation</a>), and (2) upload and attach files to an associated item (<a href="http://help.autodesk.com/view/PLM/ENU/?guid=GUID-F31EF246-A5EA-4892-B188-AA3F11DE4DBB" rel="nofollow">documentation</a>).</p>
  
  <p>In any case, the PLM 360 documentation explains things fairly clearly, and <a href="https://wqweto.wordpress.com/2011/07/12/vb6-using-wininet-to-post-binary-file/" rel="nofollow">this</a> blog post (specifically, the approach using WinHttp.WinHttpRequest.5.1) seems to do a decent job of explaining the VBA side, but I'm struggling to figure out which things are important from each of the given examples.</p>
  
  <p>Here are the main things that are puzzling me at the moment:</p>
  
  <ol>
  <li>The PLM 360 <a href="http://help.autodesk.com/view/PLM/ENU/?guid=GUID-89834BD4-BCC9-4124-BE6C-B307875DE84A" rel="nofollow">documentation</a> seems to indicate that one request is being sent in two parts, but I don't understand how to do that in VBA.</li>
  <li>The code in the blog post surrounds the binary file with <code>STR_BOUNDARY</code>. Is that necessary in all cases, or is that something that's necessary only for some APIs?</li>
  <li>The code in the blog post includes the <code>Content-Disposition</code> and a few other things in the binary portion. Again, is this necessary in all cases, or is that something that's necessary only for some APIs?</li>
  <li>The caveat to the <code>pvToByteArray</code> function is confusing to me. I understand that it is converting back to a byte array the string containing the file data, but if #3 above is not necessary in PLM 360, is it necessary to convert the file to a string and then back to a binary "blob", or does that result in it being possible to pass <code>baBuffer</code> without failure?</li>
  <li>How do I include the rest of the information in the request for creating the item? I suppose this is somewhat related to #1 above, but I don't understand how to send API calls in two parts.</li>
  </ol>
  
  <p>Ultimately, I'm posting this question here because I don't think people on the SolidWorks forum would have enough experience with REST APIs to be able to help, and <a href="http://forums.autodesk.com/t5/plm-360-general-discussion/rest-api-creating-binary-workspace-items/m-p/5917827" rel="nofollow">experience</a> shows that the people in the PLM 360 forum don't have enough experience with VBA to be able to help. StackOverflow seems like the place with the best chance of having people with experience in both areas.</p>