2

I've spent the last few days reading over different ways to implement an "Image Preview" before form submission feature on my website.

I've used HTML5 to get this working successfully on some browsers but not on all. This seems to be such a hassle so I've decided the best way to do this would be to have the image the user selects automatically upload to a temporary folder on the server so it can be displayed back to them after.

Details

This image is part of a micropost.

  • User clicks micropost text area and it expands showing them a camera image which they can click on to select an image.

  • After successful selection I'll use JQuery's trigger method to trigger the submission of a small form that uploads the file to a temp folder.

  • This will allow me to show a progress bar while the upload is taking place then display the image back to the user. It will work on all browsers.

  • Then if the user decides the image is fine they'll continue filling out the micropost forms text area and click post.

  • When post is clicked the temp image will be moved to it's permanent position and the path will be updated.

I'm using carrierwave for image upload.

In my microposts table I have an image column which holds the path of the image.

Here is where I get slightly confused. I'll have to some how get the path of the image when the micropost post button is clicked so it can be stored in microposts table but the path will be the temp path that won't be used any more because the image would have been moved to it's permanent path.

I'd really appreciate great info on a straight forward way of doing this. The web world would be so much different if web browsers were quite like cars (e.g. 4 wheels, steering wheel, windows, petrol, diesel).

4

2 に答える 2

3

写真のアップロードには、このjQueryプラグインを使用する必要があります:http://blueimp.github.com/jQuery-File-Upload/

それはあなたが必要とするものをサポートし、古くてくだらないブラウザのための実用的なソリューション(例えばiframe)にデフォルト設定されます。

楽しみ!

于 2012-05-05T14:06:28.830 に答える
1

アップロードする前にフォームの画像プレビューのみが必要な場合は、(私として)JQuery Uploadプラグインが非常に複雑で、適切に実行するのが簡単ではないことがわかります(プレビューを見ることができましたが、その後フォームが混乱しているため、画像をアップロードできませんでした)。時間がかかりすぎて諦めました。

次に、(グーグルで)深く見て、私はこの解決策を見つけました:

http://saravani.wordpress.com/2012/03/14/preview-of-an-image-before-it-is-uploaded/

コーディングは本当に簡単で高速です。

于 2013-04-22T23:05:56.663 に答える