question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Upload file to CouchDB

See original GitHub issue

I’m trying to upload an image with the following code:

$scope.onFileSelect = function(ins, files) {
  _.each(files, function(file) {
    var fileReader = new FileReader();
    fileReader.onload = function(e) {
      $timeout(function() {
        file.previewUrl = e.target.result;
      });
    };
    fileReader.readAsDataURL(file);
    $upload.upload({
      url: projectRepository.attachmentUrl(ins, file.name),
      method: "PUT",
      file: file,
    }).progress(function (evt) {
      console.log(evt);
    }).success(function(data) {
      // ...
    }).error(function(data) {
      console.log(data);
    });
  });
};

I’m uploading the file to CouchDB (which I don’t think matters since CouchDB doesn’t do any processing on the file) and the uploaded file end up with the content type “application/json”. I fixed that by setting the headers manually with

headers: { "Content-Type": file.type },

And outcommenting the line in the angular-file-upload source that sets the content type to undefined. This fixes the content type, and sets it correctly according to the filetype but the uploaded file still ends up on the server in some corrupted form that won’t show correctly in the browser.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
munkh-altaicommented, Apr 18, 2014

Hello how i change to Multiple File Input Fields in One Form

1reaction
danialfaridcommented, Dec 30, 2013

version 1.2.0 now supports this:

    var fileReader = new FileReader();
    fileReader.readAsArrayBuffer(file);
    fileReader.onload = function(e) {
        $upload.http({
            url: 'upload',
            headers: {'Content-Type': file.type},
            data: e.target.result
        }).then(function(response) {
            //success;
        }, null, function(evt) {
            $scope.progress[index] = parseInt(100.0 * evt.loaded / evt.total);
        });
    }

Read more comments on GitHub >

github_iconTop Results From Across the Web

CouchDB Attaching Files - Tutorialspoint
To do so, click on the Upload Attachment button. A dialog box will appear where you can choose the file to be uploaded....
Read more >
1.4.2. /db/doc/attachment — Apache CouchDB® 3.2 ...
Returns the file attachment associated with the document. ... Uploads the supplied content as an attachment to the specified document.
Read more >
CouchDB Attach Files to Document - YouTube
Learn how to attach files in the document using CouchDB.
Read more >
Uploading file to PouchDB/CouchDB - Stack Overflow
Now, i've got to the point where I need to add a function to upload (multiple) files to a document. (files like ....
Read more >
Learn CouchDB Attach Files in CouchDB Tutorial (19255)
With this option, you can upload a new attachment like file, image, or document, to the database. In order to do this, click...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found