Example #1
0
    function sendFile(cb) {
      var anyfetch = new Anyfetch(GLOBAL.ACCESS_TOKEN);

      var title = path.basename(filePath, path.extname(filePath));
      title = title.replace(/(_|-|\.)/g, ' ');
      title = title.charAt(0).toUpperCase() + title.slice(1);

      // Send a document to anyFetch
      var document = {
        identifier: baseIdentifier + filePath,
        document_type: 'file',
        creation_date: creationDate,
        metadata: {
          title: title
        }
      };

      var fileConfig = {
        file: absolutePath,
        filename: path.basename(filePath),
      };
      anyfetch.sendDocumentAndFile(document, fileConfig, cb);
    },
    async.each(filtered_attachments, function(attachment, cb) {
      var anyfetch = new Anyfetch(document.access_token);
      anyfetch.setApiUrl(finalCb.apiUrl);

      var docAttachment = {};
      docAttachment.metadata = {};
      docAttachment.metadata.subject = exists(mail_object.subject);
      docAttachment.identifier = document.identifier + "/" + attachment.fileName;
      docAttachment.document_type = "file";
      docAttachment.metadata = {};
      docAttachment.metadata.path = "/" + attachment.fileName;
      docAttachment.user_access = document.user_access;
      docAttachment.creation_date = changes.creation_date;
      docAttachment.related = [document.identifier,];
      changes.related.push(docAttachment.identifier);
      // File to send
      var fileConfigAttachment = {
        file: attachment.content,
        filename: attachment.fileName,
        knownLength: attachment.length
      };

      anyfetch.sendDocumentAndFile(docAttachment, fileConfigAttachment, cb);
    },