1

I am using this photo upload directive to upload images:

https://github.com/danialfarid/ng-file-upload

http://jsfiddle.net/ew4jakn5/

 $scope.upload = function (files) {
        if (files && files.length) {
            for (var i = 0; i < files.length; i++) {
                var file = files[i];
                Upload.upload({
                    url: 'https://angular-file-upload-cors-srv.appspot.com/upload',
                    fields: {
                        'username': $scope.username
                    },
                    file: file
                }).progress(function (evt) {
                    var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
                    $scope.log = 'progress: ' + progressPercentage + '% ' +
                                evt.config.file.name + '\n' + $scope.log;
                }).success(function (data, status, headers, config) {
                    $timeout(function() {
                        $scope.log = 'file: ' + config.file.name + ', Response: ' + JSON.stringify(data) + '\n' + $scope.log;
                    });
                });
            }
        }
    };

I need to add the ability to 'paste' an image from the clipboard and for that to be uploaded by ng-file-upload.

Could anyone give me pointers on how to do that?

1

2 Answers 2

2
 function handlePaste(e) {
            $log.debug(e.originalEvent.clipboardData);
            for (var i = 0 ; i < e.originalEvent.clipboardData.items.length ; i++) {
                var item = e.originalEvent.clipboardData.items[i];
                console.log("Item type: " + item.type);
                if (item.type.indexOf("image") != -1) {
                    $log.debug( item.getAsFile(), {});
                    Upload.upload({file: item.getAsFile(),
                        url: '/upload/', //upload.php script, node.js route, or servlet url
                        // method: POST or PUT,
                        // headers: {'header-key': 'header-value'},
                        // withCredentials: true,
                        data: {user_uuid: $scope.session.user.user_uuid}});
                } else {
                    alert("Discarding non-image paste data");
                }
            }
        }
Sign up to request clarification or add additional context in comments.

Comments

0

Pasting an image is the same as dropping them

<div class="img-dropper" ngf-drop="upload($files)" ng-model="context[terminatedkey]" ngf-drag-over-class="'dragover'"  tabindex="0">
    <span>Paste or drop files here</span>
</div>

and the default $scope.upload = function (file) will work

Comments

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.