Как вы добавляете несколько пар ключ / значение в узел js, используя грозный? - PullRequest
0 голосов
/ 18 октября 2019

У меня проблемы с анализом нескольких пар ключ-значение в узле js с использованием огромных данных. это моя текущая настройка.

это мой внешний интерфейс, использующий угловой

public upload(
    files: Set<File>
  ): { [key: string]: { progress: Observable<number> } } {
    // this will be the our resulting map
    const status: { [key: string]: { progress: Observable<number> } } = {};

    files.forEach(file => {
      // create a new multipart-form for every file

      const formData: FormData = new FormData();
      formData.append('file', file, file.name);
      formData.append('input', "name");


      // formData.append('name', course, course.name);
      // formData.append('text', username, username.name);
      let headers = new HttpHeaders();
      this.loadToken();
      headers.append('Authorization', this.authToken);
      headers.append('Content-type', 'application/json');


      // create a http-post request and pass the form
      // tell it to report the upload progress

      const req = new HttpRequest('POST', 'users/upload', formData,
         { headers: headers, reportProgress: true });

      // create a new progress-subject for every file
      const progress = new Subject<number>();

      // send the http-request and subscribe for progress-updates

      const startTime = new Date().getTime();
      this.https.request(req).subscribe(event => {
        if (event.type === HttpEventType.UploadProgress) {
          // calculate the progress percentage

          const percentDone = Math.round((100 * event.loaded) / event.total);
          // pass the percentage into the progress-stream
          progress.next(percentDone);
        } else if (event instanceof HttpResponse) {
          // Close the progress-stream if we get an answer form the API
          // The upload is complete
          progress.complete();
        }
      });

      // Save every progress-observable in a map of all observables
      status[file.name] = {
        progress: progress.asObservable()
      };
    });

    // return the map of progress.observables
    return status;
  }

, и это мой внутренний сервер, использующий узел js im, пытающийся выяснить, как проанализировать 'input'поле из моего интерфейса, но в настоящее время я могу только проанализировать поле 'file'.

router.post('/upload', function(req,res){
console.log(req.headers);

const form = new IncomingForm();
form.on('file', (field, file) => {
form.on('input',(filed) => {



 // form.on('course', (field, course) => {
 // form.on('username', (field, username) => {
// Do something with the file
// e.g. save it to the database
// you can access it using file.path
 const oldpath = file.path;
    const original = file.name;
    // const filename = config.myPath + original;
    //console.log(filename);
    //console.log(files);

        fs.readFile(oldpath, function (err, data) {
            if (err) throw err;

            const base64data = new Buffer(data, 'binary');
            const s3 = new AWS.S3();

            s3.putObject({
                Bucket: 'swiftyturorial',
                 Key: ''+req.headers.referer,
                Body: base64data,
                ACL: 'public-read'
            },function (res) {
                console.log(arguments);
                console.log('Successfully uploaded package.');
            });

        });


 //
...