Revision 1d5c57d3 pithos/api/functions.py
b/pithos/api/functions.py | ||
---|---|---|
98 | 98 |
elif request.method == 'MOVE': |
99 | 99 |
return object_move(request, v_account, v_container, v_object) |
100 | 100 |
elif request.method == 'POST': |
101 |
if request.META.get('CONTENT_TYPE', '').startswith('multipart/form-data'): |
|
102 |
return object_write_form(request, v_account, v_container, v_object) |
|
101 | 103 |
return object_update(request, v_account, v_container, v_object) |
102 | 104 |
elif request.method == 'DELETE': |
103 | 105 |
return object_delete(request, v_account, v_container, v_object) |
... | ... | |
680 | 682 |
response['ETag'] = meta['hash'] |
681 | 683 |
return response |
682 | 684 |
|
685 |
@api_method('POST') |
|
686 |
def object_write_form(request, v_account, v_container, v_object): |
|
687 |
# Normal Response Codes: 201 |
|
688 |
# Error Response Codes: serviceUnavailable (503), |
|
689 |
# itemNotFound (404), |
|
690 |
# unauthorized (401), |
|
691 |
# badRequest (400) |
|
692 |
|
|
693 |
if not request.FILES.has_key('X-Object-Data'): |
|
694 |
raise BadRequest('Missing X-Object-Data field') |
|
695 |
file = request.FILES['X-Object-Data'] |
|
696 |
|
|
697 |
meta = {} |
|
698 |
meta['Content-Type'] = file.content_type |
|
699 |
|
|
700 |
md5 = hashlib.md5() |
|
701 |
size = 0 |
|
702 |
hashmap = [] |
|
703 |
for data in file.chunks(backend.block_size): |
|
704 |
size += len(data) |
|
705 |
hashmap.append(backend.put_block(data)) |
|
706 |
md5.update(data) |
|
707 |
|
|
708 |
meta['hash'] = md5.hexdigest().lower() |
|
709 |
|
|
710 |
try: |
|
711 |
backend.update_object_hashmap(request.user, v_account, v_container, v_object, size, hashmap, meta, True) |
|
712 |
except NotAllowedError: |
|
713 |
raise Unauthorized('Access denied') |
|
714 |
except NameError: |
|
715 |
raise ItemNotFound('Container does not exist') |
|
716 |
|
|
717 |
response = HttpResponse(status=201) |
|
718 |
response['ETag'] = meta['hash'] |
|
719 |
return response |
|
720 |
|
|
683 | 721 |
@api_method('COPY') |
684 | 722 |
def object_copy(request, v_account, v_container, v_object): |
685 | 723 |
# Normal Response Codes: 201 |
Also available in: Unified diff