Upload assets files to S3
195131
def assets2s3():
    
    import flask_s3

    header("Assets2S3...")
    print("")
    print("Building assets files..." )
    print("")
    build_assets(application.app)
    print("")
    print("Uploading assets files to S3 ...")
    flask_s3.create_all(application.app)
    print("")
1371123
def upload_to_s3(self, source_path, bucket_name, disable_progress=False):
        

        """
        try:
            self.s3_client.head_bucket(Bucket=bucket_name)
        except botocore.exceptions.ClientError:
            # This is really stupid S3 quirk. Technically, us-east-1 one has no S3,
            # it's actually "US Standard", or something.
            # More here: https://github.com/boto/boto3/issues/125
            if self.aws_region == 'us-east-1':
                self.s3_client.create_bucket(
                    Bucket=bucket_name,
                )
            else:
                self.s3_client.create_bucket(
                    Bucket=bucket_name,
                    CreateBucketConfiguration={'LocationConstraint': self.aws_region},
                )

            if self.tags:
                tags = {
                    'TagSet': [{'Key': key, 'Value': self.tags[key]} for key in self.tags.keys()]
                }
                self.s3_client.put_bucket_tagging(Bucket=bucket_name, Tagging=tags)

        if not os.path.isfile(source_path) or os.stat(source_path).st_size == 0:
            print("Problem with source file {}".format(source_path))
            return False

        dest_path = os.path.split(source_path)[1]
        try:
            source_size = os.stat(source_path).st_size
            print("Uploading {0} ({1})..".format(dest_path, human_size(source_size)))
            progress = tqdm(total=float(os.path.getsize(source_path)), unit_scale=True, unit='B', disable=disable_progress)

            # Attempt to upload to S3 using the S3 meta client with the progress bar.
            # If we're unable to do that, try one more time using a session client,
            # which cannot use the progress bar.
            # Related: https://github.com/boto/boto3/issues/611
            try:
                self.s3_client.upload_file(
                    source_path, bucket_name, dest_path,
                    Callback=progress.update
                )
            except Exception as e:  # pragma: no cover
                self.s3_client.upload_file(source_path, bucket_name, dest_path)

            progress.close()
        except (KeyboardInterrupt, SystemExit):  # pragma: no cover
            raise
        except Exception as e:  # pragma: no cover
            print(e)
            return False
        return True
1331043
def upload_files(job, *paths)
      @log.info("Uploading assets")
      paths.each do |path|
        @log.info("Uploading files from #{path}")
        Dir.foreach(path) do |item|
          @log.info("File: #{item}")
          next if item == '.' or item == '..'
          begin
            artifact = job.report_artifact("#{path}/#{item}")
            @log.info("Artifact uploaded: #{artifact.attributes.to_s}")
          rescue => e
            @log.error("Error uploading artifact #{item}: #{e.message}")
            @log.error("  : #{e.backtrace.join("\n  : ")}")
          end
        end
      end
    end
665333
def _upload_assets_to_OSF(dlgr_id, osf_id, provider="osfstorage"):
    """"""
    root = "https://files.osf.io/v1"
    snapshot_filename = "{}-code.zip".format(dlgr_id)
    snapshot_path = os.path.join("snapshots", snapshot_filename)
    r = requests.put(
        "{}/resources/{}/providers/{}/".format(root, osf_id, provider),
        params={"kind": "file", "name": snapshot_filename},
        headers={
            "Authorization": "Bearer {}".format(config.get("osf_access_token")),
            "Content-Type": "text/plain",
        },
        data=open(snapshot_path, "rb"),
    )
    r.raise_for_status()
582082
def disk_assets
      assets = {}
      Dir["#{File.dirname(disk_path)}/**"].select{|p| File.directory?(p)}.reject {|p|
        Dir.entries(p).any?{|e| e.include? "yml"}
      }.each{|asset_path| assets.merge!(map_to_disk(asset_path)) }

      assets
    end
686439
def sync_s3(self):
        """"""
        bucket, key = self.open_s3()
        for directory in self.DIRECTORIES:
            for root, dirs, files in os.walk(directory):
                self.upload_s3((bucket, key, self.AWS_BUCKET_NAME, directory), root, files, dirs)
1066626
def upload_photos(request):
    '''
    
    '''
    upurl = ''
    if request.FILES.get("upload"):
        f = request.FILES.get("upload")
        obj = Image_File.objects.create(upload=f, is_image=True)
        obj.save()
        thumbnail_name = 'thumb' + f.name
        if getattr(settings, 'AWS_ENABLED', False):
            image_file = requests.get(obj.upload.url, stream=True)
            with open(thumbnail_name, 'wb') as destination:
                for chunk in image_file.iter_content():
                    destination.write(chunk)
        else:
            image_file = f
            with open(thumbnail_name, 'wb') as destination:
                for chunk in image_file.chunks():
                    destination.write(chunk)
        im = Image.open(destination.name)
        size = (128, 128)
        im.thumbnail(size)
        im.save(thumbnail_name)
        with open(thumbnail_name, 'rb') as imdata:
            obj.thumbnail.save(thumbnail_name, File(imdata))
        obj.save()
        os.remove(os.path.join(settings.BASE_DIR, thumbnail_name))
        upurl = "/" + obj.upload.url
    return HttpResponse(
        """<script type='text/javascript'>
        window.parent.CKEDITOR.tools.callFunction({0}, '{1}');
        </script>""".format(request.GET['CKEditorFuncNum'], upurl)
    )
1186000
def upload_gallery_file(self, folder_name, file_name, data=None, input_file_path=None,
                            prevent_share=False, content_type="image/png", scope='content/write'):
        
        if input_file_path:
            with open(input_file_path, 'rb') as f:
                data = f.read()

        if not data:
            raise ValueError('Either the data of a file or the path to a file must be provided')

        params = {
            'fileName': file_name,
            'preventShare': 'true' if prevent_share else 'false',
        }

        return _post(
            token=self.oauth.get_user_token(scope),
            uri='/user/media/file/' + urllib.quote(folder_name) + '?' + urllib.urlencode(params),
            data=data,
            content_type=content_type,
        )
236382
def _upload_s3(self, zip_file):
        '''
        
        '''
        s3_client = self._aws_session.client('s3')
        transfer = boto3.s3.transfer.S3Transfer(s3_client)
        transfer.upload_file(zip_file, self._config.s3_bucket,
                             self._config.s3_package_name())
1229142
def _add_asset_bundle(cls, path):
        
        f = "%s/assets.yml" % path
        if os.path.isfile(f):
            cls._asset_bundles.add(f)
1071005
def UploadImageAsset(client, url):
  
  # Initialize appropriate service.
  asset_service = client.GetService('AssetService', version='v201809')

  # Download the image.
  image_request = requests.get(url)

  # Create the image asset.
  image_asset = {
      'xsi_type': 'ImageAsset',
      'imageData': image_request.content,
      # This field is optional, and if provided should be unique.
      # 'assetName': 'Image asset ' + str(uuid.uuid4()),
  }

  # Create the operation.
  operation = {
      'operator': 'ADD',
      'operand': image_asset
  }

  # Create the asset and return the ID.
  result = asset_service.mutate([operation])

  return result['value'][0]['assetId']
1316189
def compile_assets(self):
        
        try:
            # Move into client dir
            curdir = os.path.abspath(os.curdir)
            client_path = os.path.join(os.path.dirname(__file__), 'longclaw', 'client')
            os.chdir(client_path)
            subprocess.check_call(['npm', 'install'])
            subprocess.check_call(['npm', 'run', 'build'])
            os.chdir(curdir)
        except (OSError, subprocess.CalledProcessError) as err:
            print('Error compiling assets:  {}'.format(err))
            raise SystemExit(1)
489471
function(awsParams) {
                        xhr.open("POST", url, true);

                        qq.obj2FormData(awsParams, formData);

                        // AWS requires the file field be named "file".
                        formData.append("file", fileOrBlob);

                        promise.success(formData);
                    }
763964
function deployS3(config) {
  if (!config.credentials.accessKeyId || !config.credentials.secretAccessKey) {
    gutil.log(
      gutil.colors.red('AWS S3 credentials missing, skipping upload...'),
    );
    return;
  }

  // create a new publisher
  const publisher = aws.create(config.credentials);

  // define custom headers
  const headers = {
    'Cache-Control': 'max-age=315360000, no-transform, public',
  };
  return (
    gulp
      .src(config.assetsPath)
      .pipe(
        rename(function(filepath) {
          filepath.dirname = path.join(config.dirname, filepath.dirname);
        }),
      )
      // gzip, Set Content-Encoding headers and add .gz extension
      .pipe(gulpIf(file => !file.path.match(/\.(mp4|ogg|webm|avi|mov|mkv)$/), aws.gzip()))
      // publisher will add Content-Length, Content-Type and headers specified above
      // If not specified it will set x-amz-acl to public-read by default
      .pipe(publisher.publish(headers))
      // create a cache file to speed up consecutive uploads
      .pipe(publisher.cache())
      // print upload updates to console
      .pipe(aws.reporter())
  );
}
688117
def upload_to_s3(self, region='us-east-1'):
        
        s3_import_cmd = "aws s3 cp {} s3://{} --profile '{}' --region {}".format(self.upload_file, self.bucket_name,
                                                                                 self.aws_project, region)
        print "Uploading to bucket {} in s3 with the cmd: {}".format(self.bucket_name, s3_import_cmd)
        # s3 upload puts DL progress to stderr
        s3_upload = subprocess.Popen(shlex.split(s3_import_cmd), stderr=subprocess.PIPE)
        while True:
            progress = s3_upload.stderr.readline()
            if progress == '' and s3_upload.poll() is not None:
                break
            if progress:
                print (progress)
        rc = s3_upload.poll()
        if rc != 0:
            raise subprocess.CalledProcessError(rc)
        print "Upload completed successfully"
470521
def upload_from_fs(fn, profile=None, label=None):
    
    if not os.path.isfile(fn):
        raise ValueError('File is not exists: {}'.format(fn))
    if profile is None:
        profile = 'default'
    conf = get_profile_configs(profile)
    with open(fn, 'rb') as f:
        if not is_image(f, types=conf['TYPES']):
            msg = (('Format of uploaded file "%(name)s" is not allowed. '
                    'Allowed formats is: %(formats)s.') %
                   {'name': fn, 'formats': ', '.join(map(lambda t: t.upper(), conf['TYPES']))})
            raise RuntimeError(msg)
        return _custom_upload(f, profile, label, conf)
977888
def generate_s3_url(files):
    """"""
    if files:
        vault = g.client.Vault.get_personal_vault()
        files = json.loads(files)
        objects = []
        for i in xrange(len(files)):
            obj = g.client.Object.create(
                vault_id=vault.id,
                object_type='file',
                filename=files[i].get('filename'),
                mimetype=files[i].get('mimetype'),
                size=files[i].get('size')
            )
            objects.append({
                'id': obj.id,
                'filename': obj.filename,
                'upload_url': obj.upload_url
            })
        return json.dumps(objects)