def callback(path): try: # Save proxy = self.proxy.current self.aes_key = AESCipher.generate_key() remote_uri = str(path) new_file_info = FileInfo( name=self.data_name.value, data_type='stream', proxy=proxy, remote_type='stream', remote_uri=remote_uri, public_key=wallet.market_client.public_key, is_published=False, created=func.current_timestamp(), aes_key=self.aes_key) fs.add_file(new_file_info) self._id = new_file_info.id encrypted_key = RSACipher.encrypt(self.aes_key) encrypted_key = Encoder.bytes_to_base64_str(encrypted_key) wallet.market_client.upload_file_info(None, None, 0, self._id, 'stream', json.dumps(remote_uri), self.data_name.value, encrypted_key) path = json.loads(path) self.uploaded.emit(path) except Exception as err: logger.error(err)
def upload_file_s3(file_path): with tempfile.TemporaryDirectory() as tmpdirname: encrypted_path = os.path.join(tmpdirname, 'encrypted.txt') logger.debug("start to encrypt") this_key = encrypt_file(file_path, encrypted_path) logger.debug("encrypt completed") file_name = list(os.path.split(file_path))[-1] s3_client = S3Storage() s3_client.upload_file(encrypted_path, file_name, "cpchain-bucket") file_name = list(os.path.split(file_path))[-1] file_size = os.path.getsize(file_path) logger.debug('start to write data into database') new_file_info = FileInfo(hashcode=str("s3_hash"), name=file_name, path=file_path, size=file_size, remote_type="s3", remote_uri=file_name, is_published=False, aes_key=this_key) add_file(new_file_info) logger.debug('file id: %s', new_file_info.id) file_id = new_file_info.id return file_id
def cb(file_uri): file_name = list(os.path.split(file_path))[-1] file_size = os.path.getsize(file_path) logger.debug('start to write data into database') if data_name: file_name = data_name with open(encrypted_path, "rb") as file: file_md5 = hashlib.md5(file.read()).hexdigest() if storage_type == 'proxy': hashcode = dict(proxy=file_uri) else: hashcode = json.loads(file_uri) hashcode['file_hash'] = file_md5 from cpchain.wallet.pages import wallet new_file_info = FileInfo(hashcode=json.dumps(hashcode), name=file_name, path=file_path, size=file_size, remote_type=str(storage_type), remote_uri=str(file_uri), public_key=wallet.market_client.public_key, is_published=False, aes_key=this_key, created=func.current_timestamp()) add_file(new_file_info) logger.debug('file id: %s', new_file_info.id) tmp.close() file_id = new_file_info.id return file_id
def upload_file_ipfs(file_path): with tempfile.TemporaryDirectory() as tmpdirname: encrypted_path = os.path.join(tmpdirname, 'encrypted.txt') print("before encrypt") this_key = encrypt_file(file_path, encrypted_path) print("after encrypt") ipfs_client = IPFSStorage() ipfs_client.connect() file_hash = ipfs_client.upload_file(encrypted_path) file_name = list(os.path.split(file_path))[-1] file_size = os.path.getsize(file_path) print("before database") new_file_info = FileInfo(hashcode=str(file_hash), name=file_name, path=file_path, size=file_size, remote_type="ipfs", remote_uri="/ipfs/" + file_name, is_published=False, aes_key=this_key) add_file(new_file_info) return file_hash
def upload_file_ipfs(file_path): with tempfile.TemporaryDirectory() as tmpdirname: encrypted_path = os.path.join(tmpdirname, 'encrypted.txt') logger.debug("start to encrypt") this_key = encrypt_file(file_path, encrypted_path) logger.debug("encrypt completed") ipfs_client = IPFSStorage() ipfs_client.connect() file_hash = ipfs_client.upload_file(encrypted_path) file_name = list(os.path.split(file_path))[-1] file_size = os.path.getsize(file_path) logger.debug('start to write data into database') new_file_info = FileInfo(hashcode=str(file_hash), name=file_name, path=file_path, size=file_size, remote_type="ipfs", remote_uri="/ipfs/" + file_hash, is_published=False, aes_key=this_key) add_file(new_file_info) logger.debug('file id: %s', new_file_info.id) file_id = new_file_info.id return file_id