Skip to content

Upload file to CouchDB #88

@paldepind

Description

@paldepind

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions