2

I tried to upload and cropping using ng-file-upload.

The problem is the cropped image become base64 format instead of 'file` format.

Here is the console.log result on testing:

console log

my html:

<div class="form-group">
     <label class="control-label">Cover</label>
     <input type="file" ngf-select ng-model="category.cover" name="cover" id="cover" ngf-pattern="image/*" accept="image/*"
     ngf-max-size="512KB" class="filestyle" data-button-name="btn-danger">

     <div ngf-drop ng-model="category.cover" ngf-pattern="image/*" class="cropAreaCover">
          <img-crop image="category.cover  | ngfDataUrl" result-image="category.croppedDataUrl" ng-init="category.croppedDataUrl=''"
                              area-type="square" area-min-size="800">
           </img-crop>
      </div>
</div>

How can I convert the cover result (base64) to file like logo result?

2 Answers 2

5

I've found it using plain javascript syntax:

var cover =Upload.dataUrltoBlob(category.croppedDataUrl);
cover = new File([cover], 'cover.jpg', {type:"image/jpg"});
Sign up to request clarification or add additional context in comments.

1 Comment

that was perfect
0

Use like this

<img ng-src="data:image/jpg;base64,{{logo}}"  / >

1 Comment

hi, isn't this code convert from file to base64? i've tried on my cover. it says invalid url.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.