J'ai un formulaire de téléchargement et un gestionnaire qui permet de télécharger des fichiers téléchargés à partir de blobstore. Le problème est lorsque je clique sur le bouton Télécharger de n'importe quel champ lié, il télécharge le même fichier à chaque fois. C'est à dire. J'ai téléchargé 3 fichiers (1.txt, 2.txt, 3.txt) et il télécharge toujours 1.txt chaque fois que j'ai cliqué sur un autre bouton de téléchargement. Vous pouvez le voir au http://my77notes.appspot.com/show (ou http://my77notes.appspot.com/upload d'abord pour télécharger vos propres fichiers). Lorsque j'ai recherché le code source, il me montre différentes clés pour tous les champs cachés. Qu'est-ce que j'ai tord?Fichier d'extraction récupéré à l'aide de Blobstore
Voici mes fichiers:
fichier modèle :
<h2>Files uploaded to Blobstore</h2>
<table border="3">
<tr>
<td>#</td>
<td>Filename</td>
<td>Content-Type</td>
<td>Creation</td>
<td>Size</td>
<td>Download</td>
</tr>
<form id="show_blob" name="show_blob" method="post" action="{{ download_blob }}">
{% for file in blob_files %}
<tr>
<td>{{ loop.index }}</td>
<td>{{ file.filename }}</td>
<td>{{ file.content_type }}</td>
<td>{{ file.creation }}</td>
<td>{{ file.size }}</td>
<td>
<input type="submit" name="download" value="Download"/>
<input type="hidden" name="blobkey" value="{{ file.key() }}" />
</td>
</tr>
{% endfor %}
</form>
</table>
handler.py
class BlobstoreServeHandler(RequestHandler, BlobstoreDownloadMixin):
def post(self):
blob_info = blobstore.BlobInfo.get(self.request.form.get('blobkey'))
return self.send_blob(blob_info, save_as=True)
urls.py
rules = [
Rule('/', endpoint='index', handler='apps.77notes.handlers.IndexPageHandler'),
Rule('/upload', endpoint='upload/html', handler = 'apps.77notes.handlers.BlobstoreUploadFormHandler'),
Rule('/upload/handler', endpoint='upload/handler', handler='apps.77notes.handlers.UploadHandler'),
Rule('/download', endpoint='download/html', handler = 'apps.77notes.handlers.BlobstoreDownloadFormHandler'),
Rule('/download/file', endpoint='download/file', handler='apps.77notes.handlers.BlobstoreServeHandler'),
Rule('/show', endpoint='show/html', handler='apps.77notes.handlers.ShowUploadedFilesHandler'),
]
les variables
blob_files = uploaded_files_to_blobstore = blobstore.BlobInfo.all()
download_blob = self.url_for('download/file')
Merci!
'ind = int ([_ [2:] pour _ en soi lf.request.form si _.startswith ('dl')] [0]) '- êtes-vous sûr que c'est un code valide? – VladG