fnp
/
audio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix
[audio.git]
/
src
/
apiclient
/
models.py
diff --git
a/src/apiclient/models.py
b/src/apiclient/models.py
index
07f804f
..
cc40143
100644
(file)
--- a/
src/apiclient/models.py
+++ b/
src/apiclient/models.py
@@
-1,7
+1,9
@@
import json
import json
+import os
from django.db import models
from django.contrib.auth.models import User
from requests_oauthlib import OAuth2Session
from django.db import models
from django.contrib.auth.models import User
from requests_oauthlib import OAuth2Session
+from requests_toolbelt.streaming_iterator import StreamingIterator
from .settings import YOUTUBE_CLIENT_ID, YOUTUBE_CLIENT_SECRET, YOUTUBE_TOKEN_URL
from .settings import YOUTUBE_CLIENT_ID, YOUTUBE_CLIENT_SECRET, YOUTUBE_TOKEN_URL
@@
-37,10
+39,11
@@
class YouTubeToken(models.Model):
token_updater=self.token_updater
)
token_updater=self.token_updater
)
- def call(self, method, url, params=None, json=None, data=None, resumable_
data
=None):
+ def call(self, method, url, params=None, json=None, data=None, resumable_
file_path
=None):
params = params or {}
params = params or {}
- if resumable_
data
:
+ if resumable_
file_path
:
params['uploadType'] = 'resumable'
params['uploadType'] = 'resumable'
+ file_size = os.stat(resumable_file_path).st_size
session = self.get_session()
response = session.request(
session = self.get_session()
response = session.request(
@@
-50,14
+53,15
@@
class YouTubeToken(models.Model):
data=data,
params=params,
headers={
data=data,
params=params,
headers={
- 'X-Upload-Content-Length': str(
len(resumable_data)
),
+ 'X-Upload-Content-Length': str(
file_size
),
'x-upload-content-type': 'application/octet-stream',
'x-upload-content-type': 'application/octet-stream',
- } if resumable_
data
else {}
+ } if resumable_
file_path
else {}
)
)
- if resumable_
data
:
+ if resumable_
file_path
:
location = response.headers['Location']
location = response.headers['Location']
- return session.put(
- url=location,
- data=resumable_data,
- headers={"Content-Type": "application/octet-stream"},
- )
+ with open(resumable_file_path, 'rb') as f:
+ return session.put(
+ url=location,
+ data=StreamingIterator(file_size, f),
+ headers={"Content-Type": "application/octet-stream"},
+ )