Skip to content

Commit 332767d

Browse files
committed
Return a JSON response for DELETE requests.
1 parent 8cf7bd8 commit 332767d

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

server/gae-go/app/main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload Plugin GAE Go Example 3.1.0
2+
* jQuery File Upload Plugin GAE Go Example 3.1.1
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2011, Sebastian Tschan
@@ -242,14 +242,23 @@ func delete(w http.ResponseWriter, r *http.Request) {
242242
if len(parts) != 3 {
243243
return
244244
}
245+
result := make(map[string]bool, 1)
245246
if key := parts[1]; key != "" {
246247
c := appengine.NewContext(r)
247248
blobKey := appengine.BlobKey(key)
248249
err := blobstore.Delete(c, blobKey)
249250
check(err)
250251
err = image.DeleteServingURL(c, blobKey)
251252
check(err)
253+
result[key] = true
252254
}
255+
jsonType := "application/json"
256+
if strings.Index(r.Header.Get("Accept"), jsonType) != -1 {
257+
w.Header().Set("Content-Type", jsonType)
258+
}
259+
b, err := json.Marshal(result)
260+
check(err)
261+
fmt.Fprintln(w, string(b))
253262
}
254263

255264
func handle(w http.ResponseWriter, r *http.Request) {

server/gae-python/main.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# jQuery File Upload Plugin GAE Python Example 2.1.0
3+
# jQuery File Upload Plugin GAE Python Example 2.1.1
44
# https://github.com/blueimp/jQuery-File-Upload
55
#
66
# Copyright 2011, Sebastian Tschan
@@ -141,7 +141,12 @@ def post(self):
141141
self.response.write(s)
142142

143143
def delete(self):
144-
blobstore.delete(self.request.get('key') or '')
144+
key = self.request.get('key') or ''
145+
blobstore.delete(key)
146+
s = json.dumps({key: True}, separators=(',', ':'))
147+
if 'application/json' in self.request.headers.get('Accept'):
148+
self.response.headers['Content-Type'] = 'application/json'
149+
self.response.write(s)
145150

146151

147152
class DownloadHandler(blobstore_handlers.BlobstoreDownloadHandler):

0 commit comments

Comments
 (0)