Skip to content

Commit

Permalink
Return a JSON response for DELETE requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
blueimp committed Dec 14, 2013
1 parent 8cf7bd8 commit 332767d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 10 additions & 1 deletion server/gae-go/app/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* jQuery File Upload Plugin GAE Go Example 3.1.0
* jQuery File Upload Plugin GAE Go Example 3.1.1
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2011, Sebastian Tschan
Expand Down Expand Up @@ -242,14 +242,23 @@ func delete(w http.ResponseWriter, r *http.Request) {
if len(parts) != 3 {
return
}
result := make(map[string]bool, 1)
if key := parts[1]; key != "" {
c := appengine.NewContext(r)
blobKey := appengine.BlobKey(key)
err := blobstore.Delete(c, blobKey)
check(err)
err = image.DeleteServingURL(c, blobKey)
check(err)
result[key] = true
}
jsonType := "application/json"
if strings.Index(r.Header.Get("Accept"), jsonType) != -1 {
w.Header().Set("Content-Type", jsonType)
}
b, err := json.Marshal(result)
check(err)
fmt.Fprintln(w, string(b))
}

func handle(w http.ResponseWriter, r *http.Request) {
Expand Down
9 changes: 7 additions & 2 deletions server/gae-python/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# jQuery File Upload Plugin GAE Python Example 2.1.0
# jQuery File Upload Plugin GAE Python Example 2.1.1
# https://github.com/blueimp/jQuery-File-Upload
#
# Copyright 2011, Sebastian Tschan
Expand Down Expand Up @@ -141,7 +141,12 @@ def post(self):
self.response.write(s)

def delete(self):
blobstore.delete(self.request.get('key') or '')
key = self.request.get('key') or ''
blobstore.delete(key)
s = json.dumps({key: True}, separators=(',', ':'))
if 'application/json' in self.request.headers.get('Accept'):
self.response.headers['Content-Type'] = 'application/json'
self.response.write(s)


class DownloadHandler(blobstore_handlers.BlobstoreDownloadHandler):
Expand Down

0 comments on commit 332767d

Please sign in to comment.