Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thomas Gambier
erp5
Commits
6ea1631d
Commit
6ea1631d
authored
Jun 05, 2012
by
Romain Courteaud
Committed by
Sebastien Robin
Aug 07, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BigFile client example.
parent
dff53681
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
+92
-0
product/ERP5/bin/bigfile_client_example.py
product/ERP5/bin/bigfile_client_example.py
+92
-0
No files found.
product/ERP5/bin/bigfile_client_example.py
0 → 100644
View file @
6ea1631d
input_file
=
open
(
'input_file.webm'
,
'r'
)
import
httplib
connection
=
httplib
.
HTTPConnection
(
'192.168.242.68:12001'
)
import
base64
base64string
=
base64
.
encodestring
(
'zope:insecure'
)[:
-
1
]
n
=
1
<<
20
######################################
# Create new document
######################################
headers
=
{
'Authorization'
:
'Basic %s'
%
base64string
,
}
connection
.
request
(
'POST'
,
"/erp5/portal_contributions/newContent?"
\
"portal_type=Video&filename=input_file.webm&container_path=video_module&data="
,
""
,
headers
)
result
=
connection
.
getresponse
()
path
=
result
.
getheader
(
"X-Document-Location"
)
result
.
close
()
path
=
'/%s'
%
'/'
.
join
(
path
.
split
(
'/'
)[
3
:])
print
path
######################################
# Upload chunks
######################################
input_file
.
seek
(
0
,
2
)
end
=
input_file
.
tell
()
input_file
.
seek
(
0
)
pos
=
input_file
.
tell
()
first
=
True
while
pos
<
end
:
next_pos
=
pos
+
n
if
next_pos
>
end
:
next_pos
=
end
body_content
=
input_file
.
read
(
next_pos
-
pos
)
if
first
:
headers
=
{
'Authorization'
:
'Basic %s'
%
base64string
,
}
else
:
headers
=
{
'Authorization'
:
'Basic %s'
%
base64string
,
'Content-Range'
:
'bytes %i-%i/%i'
%
(
pos
,
next_pos
-
1
,
next_pos
),
}
connection
.
request
(
'PUT'
,
path
,
body_content
,
headers
)
result
=
connection
.
getresponse
()
pos
=
input_file
.
tell
()
first
=
False
######################################
# Download chunks
######################################
output_file
=
open
(
'output_file.webm'
,
'wb'
)
output_file
.
seek
(
0
)
headers
=
{
'Authorization'
:
'Basic %s'
%
base64string
,
'Content-Range'
:
'bytes */*'
,
}
connection
.
request
(
'PUT'
,
path
,
''
,
headers
)
result
=
connection
.
getresponse
()
filerange
=
result
.
getheader
(
'Range'
)
size
=
int
(
filerange
.
split
(
'-'
)[
1
])
pos
=
0
while
pos
<
size
:
next_pos
=
pos
+
n
if
next_pos
>
size
:
next_pos
=
size
headers
=
{
'Authorization'
:
'Basic %s'
%
base64string
,
'Range'
:
'bytes=%s-%s'
%
(
pos
,
next_pos
),
}
connection
.
request
(
'GET'
,
path
,
''
,
headers
)
result
=
connection
.
getresponse
()
output_file
.
write
(
result
.
read
())
result
.
close
()
pos
=
output_file
.
tell
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment