Esempio n. 1
0
    def upload_part(self, seq, offset, chunk_size, labels, buffer = '', remote_status = None):
        """
        Upload a file chunk
        http://docs.amazonwebservices.com/AmazonS3/latest/API/index.html?mpUploadUploadPart.html
        """
        # TODO implement Content-MD5
        debug("Uploading part %i of %r (%s bytes)" % (seq, self.upload_id, chunk_size))

        if remote_status is not None:
            if int(remote_status['size']) == chunk_size:
                checksum = calculateChecksum(buffer, self.file, offset, chunk_size, self.s3.config.send_chunk)
                remote_checksum = remote_status['checksum'].strip('"\'')
                if remote_checksum == checksum:
                    warning("MultiPart: size and md5sum match for %s part %d, skipping." % (self.uri, seq))
                    self.parts[seq] = remote_status['checksum']
                    return
                else:
                    warning("MultiPart: checksum (%s vs %s) does not match for %s part %d, reuploading."
                            % (remote_checksum, checksum, self.uri, seq))
            else:
                warning("MultiPart: size (%d vs %d) does not match for %s part %d, reuploading."
                        % (int(remote_status['size']), chunk_size, self.uri, seq))

        headers = { "content-length": str(chunk_size) }
        query_string = "?partNumber=%i&uploadId=%s" % (seq, encode_to_s3(self.upload_id))
        request = self.s3.create_request("OBJECT_PUT", uri = self.uri, headers = headers, extra = query_string)
        response = self.s3.send_file(request, self.file, labels, buffer, offset = offset, chunk_size = chunk_size)
        self.parts[seq] = response["headers"]["etag"]
        return response
Esempio n. 2
0
    def upload_part(self,
                    seq,
                    offset,
                    chunk_size,
                    labels,
                    buffer='',
                    remote_status=None):
        """
        Upload a file chunk
        http://docs.amazonwebservices.com/AmazonS3/latest/API/index.html?mpUploadUploadPart.html
        """
        # TODO implement Content-MD5
        debug("Uploading part %i of %r (%s bytes)" %
              (seq, self.upload_id, chunk_size))

        if remote_status is not None:
            if int(remote_status['size']) == chunk_size:
                checksum = calculateChecksum(buffer, self.file, offset,
                                             chunk_size,
                                             self.s3.config.send_chunk)
                remote_checksum = remote_status['checksum'].strip('"\'')
                if remote_checksum == checksum:
                    warning(
                        "MultiPart: size and md5sum match for %s part %d, skipping."
                        % (self.uri, seq))
                    self.parts[seq] = remote_status['checksum']
                    return
                else:
                    warning(
                        "MultiPart: checksum (%s vs %s) does not match for %s part %d, reuploading."
                        % (remote_checksum, checksum, self.uri, seq))
            else:
                warning(
                    "MultiPart: size (%d vs %d) does not match for %s part %d, reuploading."
                    % (int(remote_status['size']), chunk_size, self.uri, seq))

        headers = {"content-length": str(chunk_size)}
        query_string = "?partNumber=%i&uploadId=%s" % (
            seq, encode_to_s3(self.upload_id))
        request = self.s3.create_request("OBJECT_PUT",
                                         uri=self.uri,
                                         headers=headers,
                                         extra=query_string)
        response = self.s3.send_file(request,
                                     self.file,
                                     labels,
                                     buffer,
                                     offset=offset,
                                     chunk_size=chunk_size)
        self.parts[seq] = response["headers"]["etag"]
        return response