def upload(self, path): """Upload media Returns the media ID on success. The media ID is used when sending the snap. """ if not os.path.exists(path): raise ValueError('No such file: {0}'.format(path)) with open(path, 'rb') as f: data = f.read() media_type = get_media_type(data) if media_type is None: raise ValueError('Could not determine media type for given data') media_id = make_media_id(self.username) now = str(timestamp()) r = self._request('/ph/upload', { 'media_id': media_id, 'type': media_type, 'timestamp': now, 'username': self.username, 'zipped': '0' }, {'now': now, 'gauth': self._get_gauth()}, files={'data': data}) return media_id if len(r.content) == 0 else None
def upload(self, path): """Upload media Returns the media ID on success. The media ID is used when sending the snap. """ if not os.path.exists(path): raise ValueError('No such file: {0}'.format(path)) with open(path, 'rb') as f: data = f.read() media_type = get_media_type(data) if media_type is None: raise ValueError('Could not determine media type for given data') media_id = make_media_id(self.username) now = str(timestamp()) r = self._request('/ph/upload', { 'media_id': media_id, 'type': media_type, 'timestamp': now, 'username': self.username, 'zipped': '0' }, { 'now': now, 'gauth': self._get_gauth() }, files={'data': data}) return media_id if len(r.content) == 0 else None
def upload_raw(self, data): """Upload media Returns the media ID on success. The media ID is used when sending the snap. """ media_type = get_media_type(data) if media_type is None: raise ValueError('Could not determine media type for given data') media_id = make_media_id(self.username) now = str(timestamp()) r = self._request('/ph/upload', { 'media_id': media_id, 'type': media_type, 'timestamp': now, 'username': self.username, 'zipped': '0' }, {'now': now, 'gauth': self._get_gauth()}, files={'data': data}) return media_id if len(r.content) == 0 else None