<commit_before>'use strict';

const path = require('path');

const fs = require('fs-extra');
const { S3 } = require('aws-sdk');
const multer = require('multer');

const s3 = new S3();
const upload = multer({ dest: `${__dirname}/../temp-assets` });

module.exports = fieldName => (req, res, next) => {
  upload.single(fieldName)(req, res, err => {
    if (err) return next(err);
    if (!req.file) return next(new Error('validation failed no file added'));

    s3
      .upload({
        ACL: 'public-read',
        Bucket: process.env.AWS_BUCKET,
        Key: `${req.file.filename}${path.extname(req.file.originalname)}`,
        Body: fs.createReadStream(req.file.path)
      })
      .promise()
      .then(s3Data => {
        req.s3Data = s3Data;<commit_msg>added more c.logs for heroku help<commit_after>'use strict';

const path = require('path');

const fs = require('fs-extra');
const { S3 } = require('aws-sdk');
const multer = require('multer');

const s3 = new S3();
const upload = multer({ dest: `${__dirname}/../temp-assets` });

module.exports = fieldName => (req, res, next) => {
  upload.single(fieldName)(req, res, err => {
    if (err) return next(err);
    if (!req.file) return next(new Error('validation failed no file added'));

    console.log('fieldName', fieldName);
    console.log('req', req);
    console.log('process.env.AWS_BUCKET', process.env.AWS_BUCKET);

    s3
      .upload({
        ACL: 'public-read',
        Bucket: process.env.AWS_BUCKET,
        Key: `${req.file.filename}${path.extname(req.file.originalname)}`,
        Body: fs.createReadStream(req.file.path)
      })
      .promise()
      .then(s3Data => {
        req.s3Data = s3Data;
{'fraction_non_alphanumeric': 0.1807372175980975, 'fraction_numerical': 0.008323424494649227, 'mean_word_length': 3.197007481296758, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '786538', 'n_tokens_mistral': 568, 'n_tokens_neox': 569, 'n_words': 126}