Forum Discussion

Joel-Hwang's avatar
Joel-Hwang
Ideator I
5 years ago
Solved

How can I upload blob data to vault in javascript?

I have a blob from the clipboard. Basically It is an image. I put the blob data in an img tag.

So I wanna upload the blob data to the vault and use it as an Image property.

Is there any idea to upload blob to vault in javascript?

2 Replies

    • Joel-Hwang's avatar
      Joel-Hwang
      Ideator I

      Thank you. I solved the problem thanks to you.

      I made a html component in form like below.

      When copy and paste an image from clipboard, it will be uploaded in vault.

      and the uploaded file will be Item's image property. 

          <div>

              <img src="" id="pastedImage">

          </div>

       

          <script>

                  document.onpaste = function(event) {

                      var items = event.clipboardData.items;

                      console.log(JSON.stringify(items)); // will give you the mime types

                      var blob = items[0].getAsFile();

                      var reader = new FileReader();

                      reader.onload = function(event) {

                          console.log(event.target.result);

                          document.querySelector('#pastedImage').src = event.target.result;

                          var file = new File([blob],'test.png',{type:"image/png"});

                          var newFile = aras.newFileItem(file);

                          var fileId = newFile.getAttribute("id");

                          var fileItem = aras.IomInnovator.newItem();

                          fileItem.loadAML(newFile.xml);

                          fileItem = fileItem.apply();

                          window.handleItemChange("_paste_image","vault:///?fileId="+fileId);       

                      }; // data url 

                      reader.readAsDataURL(blob);

                  }

       

          </script>