implementation for purchase import job using file upload
549352
def process_purchase_import_job_from_file(file_path, report_email = nil, postback_url = nil, options = {})
      data = options
      data['file'] = file_path
      process_job(:purchase_import, data, report_email, postback_url, 'file')
    end
559785
async function uploadFiles( store, session, caslib, datadir ) {
    let files = readdir(datadir);
    let executeCmd = session.links('execute');

    for (let i = 0 ; i < files.length ;i++) {
    
        let parms = { caslib: caslib, name: files[i],  quiet : true};
        await store.runAction(session, {action: 'table.dropTable', data: parms})

        parms = { caslib: caslib, source: files[i],quiet : true};
        await store.runAction(session, {action: 'table.deleteSource', data: parms})

        parms = {
            rstore: { name: files[i], caslib: caslib, replace: true},
            store : readFile(files[i], datadir)
        };
        payload = { action: 'aStore.upload', data: parms };
        console.log( `uploading  ${files[i]}`);
        await store.runAction(session, payload);
        
        parms = { rstore: { name: files[i], caslib: caslib } };
        payload = { action: 'aStore.describe', data: parms };
        await store.runAction(session, payload);
       
        parms = {
            caslib : caslib,
            name   : files[i],
            replace: true,
            table: {
                caslib: caslib,
                name  : files[i]
            }
        };
        payload ={action: 'table.save', data: parms};
        await store.runAction(session, payload);

    }
}
433193
def _upload(self, project_id, updating, file_path, language_code=None,
                overwrite=False, sync_terms=False, tags=None, fuzzy_trigger=None):
        
        options = [
            self.UPDATING_TERMS,
            self.UPDATING_TERMS_TRANSLATIONS,
            self.UPDATING_TRANSLATIONS
        ]
        if updating not in options:
            raise POEditorArgsException(
                'Updating arg must be in {}'.format(options)
            )

        options = [
            self.UPDATING_TERMS_TRANSLATIONS,
            self.UPDATING_TRANSLATIONS
        ]
        if language_code is None and updating in options:
            raise POEditorArgsException(
                'Language code is required only if updating is '
                'terms_translations or translations)'
            )

        if updating == self.UPDATING_TRANSLATIONS:
            tags = None
            sync_terms = None

        # Special content type:
        tags = tags or ''
        language_code = language_code or ''
        sync_terms = '1' if sync_terms else '0'
        overwrite = '1' if overwrite else '0'
        fuzzy_trigger = '1' if fuzzy_trigger else '0'
        project_id = str(project_id)

        with open(file_path, 'r+b') as local_file:
            data = self._run(
                url_path="projects/upload",
                id=project_id,
                language=language_code,
                file=local_file,
                updating=updating,
                tags=tags,
                sync_terms=sync_terms,
                overwrite=overwrite,
                fuzzy_trigger=fuzzy_trigger
            )
        return data['result']
286154
def importFile(self, srcUrl, sharedFileName=None):
        
        self._assertContextManagerUsed()
        return self._jobStore.importFile(srcUrl, sharedFileName=sharedFileName)
888412
def Import(context, request):
    
    form = request.form
    # TODO form['file'] sometimes returns a list
    infile = form['instrument_results_file'][0] if \
        isinstance(form['instrument_results_file'], list) \
        else form['instrument_results_file']
    override = form['results_override']
    artoapply = form['artoapply']
    instrument = form.get('instrument', None)
    errors = []
    logs = []

    # Load the most suitable parser according to file extension/options/etc...
    parser = None
    if not hasattr(infile, 'filename'):
        errors.append(_("No file selected"))
    parser = GCMSQP2010SECSVParser(infile)

    if parser:
        # Load the importer
        status = ['sample_received', 'attachment_due', 'to_be_verified']
        if artoapply == 'received':
            status = ['sample_received']
        elif artoapply == 'received_tobeverified':
            status = ['sample_received', 'attachment_due', 'to_be_verified']

        over = [False, False]
        if override == 'nooverride':
            over = [False, False]
        elif override == 'override':
            over = [True, False]
        elif override == 'overrideempty':
            over = [True, True]

        importer = GCMSQP2010SEImporter(parser=parser,
                                        context=context,
                                        allowed_ar_states=status,
                                        allowed_analysis_states=None,
                                        override=over,
                                        instrument_uid=instrument)
        tbex = ''
        try:
            importer.process()
        except:
            tbex = traceback.format_exc()
        errors = importer.errors
        logs = importer.logs
        warns = importer.warns
        if tbex:
            errors.append(tbex)

    results = {'errors': errors, 'log': logs, 'warns': warns}

    return json.dumps(results)
885577
def upload(client, source_dir):
    """"""
    print('')
    print('upload inappproducs')
    print('---------------------')

    products_folder = os.path.join(source_dir, 'products')
    product_files = filter(os.path.isfile, list_dir_abspath(products_folder))

    current_product_skus = map(lambda product: product['sku'], client.list_inappproducts())
    print(current_product_skus)
    for product_file in product_files:
        with open(product_file) as product_file:
            product = json.load(product_file)
        #check if the product is new
        sku = product['sku']
        product['packageName'] = client.package_name
        print(sku)
        if sku in current_product_skus:
            print("update product {0}".format(sku))
            client.update_inappproduct(product, sku)
        else:
            print("create product {0}".format(sku))
            client.insert_inappproduct(product)
752970
function transferSingleFile(sfXML, dir, callback){
  var xmlParser; 
  var groups;
  var responders = [];
  var fileList = [];
  var entry;
  var responder;
  var stat;

  if(typeof sfXML === 'undefined'){
    throw new Error('No input file specified');
  }

  if(!/\.xml$/.test(sfXML)){
    throw new Error('Input file must be a xml file!');
  }

  sfXML = sfXML.indexOf(path.sep) === 0 ? sfXML : path.join(process.pwd, sfXML);

  xmlParser = new xml2js.Parser();

  fs.readFile(sfXML, function(err, xml){
    if(err){ throw err; }

    xmlParser.parseString(xml, function(err, result){
      var groupParser = function(group){
        var groupId;
        var resources;

        if(typeof group['$'] === 'undefined'){
          return;
        }

        groupId = group['$']['id'];

        if(typeof groupId !== 'undefined'){
          resources = group['resource'];
          entry = {
            comment: '// pattern for ' + groupId,
            pattern: groupId,
            responder: {
              dir: dir || 'fill the dir',
              src: []
            }
          };

          responder = entry.responder;

          if(typeof resources === 'object' && 
              typeof resources['$'] === 'object' && 
              typeof resources['$']['uri'] === 'string'){

            responder.src.push(resources['$']['uri']);

          }

          if(Array.isArray(resources)){
            resources.forEach(function(resource){
              if(typeof resource['$'] === 'object' && 
                  typeof resource['$']['uri'] === 'string'){
                responder.src.push(resource['$']['uri']);
              }
            });
          }
          responders.push(entry);

        }
      }
      groups = result.groupdefinition.groups[0].group;
      if(Array.isArray(groups)){
        groups.forEach(groupParser);
      }else if(typeof groups === 'object'){
        groupParser(groups);
      }
    });

    _getRuleAsString(responders, callback);
    
  });

}
367992
def workflow_script_import(self):
        
        bsc = getToolByName(self, 'bika_setup_catalog')
        client = self.aq_parent

        title = _('Submitting Sample Import')
        description = _('Creating and initialising objects')
        bar = ProgressBar(self, self.REQUEST, title, description)
        notify(InitialiseProgressBar(bar))

        profiles = [x.getObject() for x in bsc(portal_type='AnalysisProfile')]

        gridrows = self.schema['SampleData'].get(self)
        row_cnt = 0
        for therow in gridrows:
            row = deepcopy(therow)
            row_cnt += 1

            # Profiles are titles, profile keys, or UIDS: convert them to UIDs.
            newprofiles = []
            for title in row['Profiles']:
                objects = [x for x in profiles
                           if title in (x.getProfileKey(), x.UID(), x.Title())]
                for obj in objects:
                    newprofiles.append(obj.UID())
            row['Profiles'] = newprofiles

            # Same for analyses
            newanalyses = set(self.get_row_services(row) +
                              self.get_row_profile_services(row))
            # get batch
            batch = self.schema['Batch'].get(self)
            if batch:
                row['Batch'] = batch.UID()
            # Add AR fields from schema into this row's data
            row['ClientReference'] = self.getClientReference()
            row['ClientOrderNumber'] = self.getClientOrderNumber()
            contact_uid =\
                self.getContact().UID() if self.getContact() else None
            row['Contact'] = contact_uid
            # Creating analysis request from gathered data
            ar = create_analysisrequest(
                client,
                self.REQUEST,
                row,
                analyses=list(newanalyses),)

            # progress marker update
            progress_index = float(row_cnt) / len(gridrows) * 100
            progress = ProgressState(self.REQUEST, progress_index)
            notify(UpdateProgressEvent(progress))

        # document has been written to, and redirect() fails here
        self.REQUEST.response.write(
            '<script>document.location.href="%s"</script>' % (
                self.absolute_url()))
243347
def stage_import_from_file(self, fd, filename='upload.gz'):
        
        schema = ImportSchema()
        resp = self.service.post(self.base,
                                 files={'file': (filename, fd)})
        return self.service.decode(schema, resp)
558520
public RESTImportTaskList uploadFile(Integer importJobId, File file, String sourceSrs) throws Exception {

        LOG.debug("Uploading file " + file.getName() + " to import job " + importJobId);

        Response httpResponse = HttpUtil.post(
            this.addEndPoint(importJobId + "/tasks"),
            file,
            this.username,
            this.password
        );

        HttpStatus responseStatus = httpResponse.getStatusCode();
        if (responseStatus == null || !responseStatus.is2xxSuccessful()) {
            throw new GeoServerRESTImporterException("Error while uploading the file.");
        }

        LOG.debug("Successfully uploaded the file to import job " + importJobId);

        RESTImportTaskList importTaskList = null;
        // check, if it is a list of import tasks (for multiple layers)
        try {
            importTaskList = mapper.readValue(httpResponse.getBody(), RESTImportTaskList.class);
            LOG.debug("Imported file " + file.getName() + " contains data for multiple layers.");
            return importTaskList;
        } catch (Exception e) {
            LOG.debug("Imported file " + file.getName() + " likely contains data for single " +
                "layer. Will check this now.");
            try {
                RESTImportTask importTask = mapper.readValue(httpResponse.getBody(), RESTImportTask.class);
                if (importTask != null) {
                    importTaskList = new RESTImportTaskList();
                    importTaskList.add(importTask);
                    LOG.debug("Imported file " + file.getName() + " contains data for a single layer.");
                }
                return importTaskList;
            } catch (Exception ex) {
                LOG.info("It seems that the SRS definition source file can not be interpreted by " +
                    "GeoServer / GeoTools. Try to set SRS definition to " + sourceSrs + ".");

                File updatedGeoTiff = null;
                try {
                    if (!StringUtils.isEmpty(sourceSrs)) {
                        // "First" recursion: try to add prj file to ZIP.
                        updatedGeoTiff = addPrjFileToArchive(file, sourceSrs);
                    } else {
                        // At least second recursion: throw exception since SRS definition
                        // could not be set.
                        throw new GeoServerRESTImporterException("Could not set SRS definition "
                            + "of GeoTIFF.");
                    }
                } catch (ZipException ze) {
                    throw new GeoServerRESTImporterException("No valid ZIP file given containing "
                        + "GeoTiff datasets.");
                }

                if (updatedGeoTiff != null) {
                    importTaskList = uploadFile(importJobId, updatedGeoTiff, null);
                    return importTaskList;
                }
            }
        }

        return null;
    }
773761
def import_file(self, ):
        
        tfi = self.get_taskfileinfo_selection()
        if tfi:
            self.reftrack.import_file(tfi)
899468
def upload(self, num_iid, properties, session, id=None, image=None, position=None):
        ''''''
        request = TOPRequest('taobao.item.propimg.upload')
        request['num_iid'] = num_iid
        request['properties'] = properties
        if id!=None:
            request['id'] = id
        if position!=None:
            request['position'] = position
        if image!=None:
            request['image'] = image
        self.create(self.execute(request, session)['prop_img'])
        return self
1202074
def _upload(self, obj_name, content, content_type, content_encoding,
            content_length, etag, chunked, chunk_size, headers):
        
        if content_type is not None:
            headers["Content-Type"] = content_type
        if content_encoding is not None:
            headers["Content-Encoding"] = content_encoding
        if isinstance(content, six.string_types):
            fsize = len(content)
        else:
            if chunked:
                fsize = None
            elif content_length is None:
                fsize = get_file_size(content)
            else:
                fsize = content_length
        if fsize is None or fsize <= MAX_FILE_SIZE:
            # We can just upload it as-is.
            return self._store_object(obj_name, content=content, etag=etag,
                    chunked=chunked, chunk_size=chunk_size, headers=headers)
        # Files larger than MAX_FILE_SIZE must be segmented
        # and uploaded separately.
        num_segments = int(math.ceil(float(fsize) / MAX_FILE_SIZE))
        digits = int(math.log10(num_segments)) + 1
        # NOTE: This could be greatly improved with threading or other
        # async design.
        for segment in range(num_segments):
            sequence = str(segment + 1).zfill(digits)
            seg_name = "%s.%s" % (obj_name, sequence)
            with utils.SelfDeletingTempfile() as tmpname:
                with open(tmpname, "wb") as tmp:
                    tmp.write(content.read(MAX_FILE_SIZE))
                with open(tmpname, "rb") as tmp:
                    # We have to calculate the etag for each segment
                    etag = utils.get_checksum(tmp)
                    self._store_object(seg_name, content=tmp, etag=etag,
                            chunked=False, headers=headers)
        # Upload the manifest
        headers.pop("ETag", "")
        headers["X-Object-Manifest"] = "%s/%s." % (self.name, obj_name)
        self._store_object(obj_name, content=None, headers=headers)
940699
def _upload_file(compute, project_id, file_path, path):
    
    path = "/projects/{}/files/{}".format(project_id, path.replace("\\", "/"))
    with open(file_path, "rb") as f:
        yield from compute.http_query("POST", path, f, timeout=None)
512859
def upload_data(job, master_ip, inputs, hdfs_name, upload_name, spark_on_toil):
    

    if mock_mode():
        truncate_file(master_ip, hdfs_name, spark_on_toil)

    log.info("Uploading output BAM %s to %s.", hdfs_name, upload_name)
    call_conductor(job, master_ip, hdfs_name, upload_name, memory=inputs.memory)
    remove_file(master_ip, hdfs_name, spark_on_toil)
65324
function upload() {
      stop_loop = false;

      if (!files) {
        opts.error(errors[0]);
        return false;
      }

      if (opts.allowedfiletypes.push && opts.allowedfiletypes.length) {
        for(var fileIndex = files.length;fileIndex--;) {
          if(!files[fileIndex].type || $.inArray(files[fileIndex].type, opts.allowedfiletypes) < 0) {
            opts.error(errors[3], files[fileIndex]);
            return false;
          }
        }
      }

      var filesDone = 0,
          filesRejected = 0;

      if (files_count > opts.maxfiles && opts.queuefiles === 0) {
        opts.error(errors[1]);
        return false;
      }

      // Define queues to manage upload process
      var workQueue = [];
      var processingQueue = [];
      var doneQueue = [];

      // Add everything to the workQueue
      for (var i = 0; i < files_count; i++) {
        workQueue.push(i);
      }

      // Helper function to enable pause of processing to wait
      // for in process queue to complete
      var pause = function(timeout) {
        setTimeout(process, timeout);
        return;
      };

      // Process an upload, recursive
      var process = function() {

        var fileIndex;

        if (stop_loop) {
          return false;
        }

        // Check to see if are in queue mode
        if (opts.queuefiles > 0 && processingQueue.length >= opts.queuefiles) {
          return pause(opts.queuewait);
        } else {
          // Take first thing off work queue
          fileIndex = workQueue[0];
          workQueue.splice(0, 1);

          // Add to processing queue
          processingQueue.push(fileIndex);
        }

        try {
          if (beforeEach(files[fileIndex]) !== false) {
            if (fileIndex === files_count) {
              return;
            }
            var reader = new FileReader(),
                max_file_size = 1048576 * opts.maxfilesize;

            reader.index = fileIndex;
            if (files[fileIndex].size > max_file_size) {
              opts.error(errors[2], files[fileIndex], fileIndex);
              // Remove from queue
              processingQueue.forEach(function(value, key) {
                if (value === fileIndex) {
                  processingQueue.splice(key, 1);
                }
              });
              filesRejected++;
              return true;
            }

            reader.onloadend = !opts.beforeSend ? send : function (e) {
              opts.beforeSend(files[fileIndex], fileIndex, function () { send(e); });
            };

            reader.readAsBinaryString(files[fileIndex]);

          } else {
            filesRejected++;
          }
        } catch (err) {
          // Remove from queue
          processingQueue.forEach(function(value, key) {
            if (value === fileIndex) {
              processingQueue.splice(key, 1);
            }
          });
          opts.error(errors[0]);
          return false;
        }

        // If we still have work to do,
        if (workQueue.length > 0) {
          process();
        }
      };

      var send = function(e) {

        var fileIndex = ((typeof(e.srcElement) === "undefined") ? e.target : e.srcElement).index;

        // Sometimes the index is not attached to the
        // event object. Find it by size. Hack for sure.
        if (e.target.index === undefined) {
          e.target.index = getIndexBySize(e.total);
        }

        var xhr = new XMLHttpRequest(),
            upload = xhr.upload,
            file = files[e.target.index],
            index = e.target.index,
            start_time = new Date().getTime(),
            boundary = '------multipartformboundary' + (new Date()).getTime(),
            global_progress_index = global_progress.length,
            builder,
            newName = rename(file.name),
            mime = file.type;

        if (typeof newName === "string") {
          builder = getBuilder(newName, e.target.result, mime, boundary);
        } else {
          builder = getBuilder(file.name, e.target.result, mime, boundary);
        }

        upload.index = index;
        upload.file = file;
        upload.downloadStartTime = start_time;
        upload.currentStart = start_time;
        upload.currentProgress = 0;
        upload.global_progress_index = global_progress_index;
        upload.startData = 0;
        upload.addEventListener("progress", progress, false);

        xhr.open("POST", opts.url, true);
        xhr.setRequestHeader('content-type', 'multipart/form-data; boundary=' + boundary);

        // Add headers
        $.each(opts.headers, function(k, v) {
          xhr.setRequestHeader(k, v);
        });

        xhr.sendAsBinary(builder);

        global_progress[global_progress_index] = 0;
        globalProgress();

        opts.uploadStarted(index, file, files_count);

        xhr.onload = function() {
            var serverResponse = null;

            if (xhr.responseText) {
              try {
                serverResponse = jQuery.parseJSON(xhr.responseText);
              }
              catch (e) {
                serverResponse = xhr.responseText;
              }
            }

            var now = new Date().getTime(),
                timeDiff = now - start_time,
                result = opts.uploadFinished(index, file, serverResponse, timeDiff, xhr);
            filesDone++;

            // Remove from processing queue
            processingQueue.forEach(function(value, key) {
              if (value === fileIndex) {
                processingQueue.splice(key, 1);
              }
            });

            // Add to donequeue
            doneQueue.push(fileIndex);

            // Make sure the global progress is updated
            global_progress[global_progress_index] = 100;
            globalProgress();

            if (filesDone === (files_count - filesRejected)) {
              afterAll();
            }
            if (result === false) {
              stop_loop = true;
            }
          

          // Pass any errors to the error option
          if (xhr.status < 200 && xhr.status > 299) {
            opts.error(xhr.statusText);
          }
        };
      };

      // Initiate the processing loop
      process();
    }
507613
function import_file()
    {
        $uid     = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST);
        $mbox    = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST);
        $mime_id = rcube_utils::get_input_value('_part', rcube_utils::INPUT_POST);
        $storage = $this->rc->get_storage();
        $engine  = $this->enigma->load_engine();

        if ($uid && $mime_id) {
            // Note: we get the attachment body via rcube_message class
            // to support keys inside encrypted messages (#5285)
            $message = new rcube_message($uid, $mbox);

            // Check if we don't need to ask for password again
            foreach ($engine->decryptions as $status) {
                if ($status instanceof enigma_error) {
                    if ($status->getCode() == enigma_error::BADPASS) {
                        $this->password_prompt($status, array(
                                'input_uid'    => $uid,
                                'input_mbox'   => $mbox,
                                'input_part'   => $mime_id,
                                'input_task'   => 'mail',
                                'input_action' => 'plugin.enigmaimport',
                                'action'       => '?',
                                'iframe'       => true,
                        ));
                        $this->rc->output->send($this->rc->output->type == 'html' ? 'iframe' : null);
                        return;
                    }
                }
            }

            if ($engine->is_keys_part($message->mime_parts[$mime_id])) {
                $part = $message->get_part_body($mime_id);
            }
        }

        if ($part && is_array($result = $engine->import_key($part))) {
            $this->rc->output->show_message('enigma.keysimportsuccess', 'confirmation',
                array('new' => $result['imported'], 'old' => $result['unchanged']));
        }
        else {
            $this->rc->output->show_message('enigma.keysimportfailed', 'error');
        }

        $this->rc->output->send($this->rc->output->type == 'html' ? 'iframe' : null);
    }