Blobstore Together with Other Input in GAE - google-app-engine

I understand that uploading blob in Google App Engine is something like this:
<%
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
%>
<form action="<%= blobstoreService.createUploadUrl("/upload") %>" method="post" enctype="multipart/form-data">
<input type="file" name="myFile">
<input type="submit" value="Submit">
</form>
Is it possible to save other input field? Let say we have other input in a form.
<input type="text" name="str" />

The answer is yes, it is possible. I'm successfully doing what you're asking about - uploading files and text on the same request in GAE. You just handle the request and its parameters in your request handler.

Related

Upload a picture to database with laravel

i ve created a database in localhost and table in it called gallery. I want to upload and store pictures there but i m stuck.. Can you please give me any guides or tutorial how to do it? Thanks.
upload file just refer to laravel document
for example photo is the name fo file in form
<form action="xxx" method="post" enctype="multipart/form-data">
<input type="file" name="photo" />
<input type="submit" value="update" />
</form>
store the file then return file's path in filesystem
$path = $request->photo->storeAs('images', 'filename.jpg');
$path = $request->photo->storeAs('images', 'filename.jpg', 's3');
then store the $path to your database
First you need the form on your view (don't forget the csrf token):
<form action="/image-upload" method="POST" enctype="multipart/form-data">
#csrf
<input type="file" name="image">
<button type="submit">Upload</button>
</form>
And on your routes file add the route for POST method:
Route::post('image-upload', 'ImageUploadController#imageUploadPost');
Then on your Controller create the function that will validate and
move your image to the 'public/images' folder.
public function imageUploadPost()
{
request()->validate([
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$imageName = time().'.'.request()->image->getClientOriginalExtension();
request()->image->move(public_path('images'), $imageName);
}

Angular JS URL Validation

We have to validate a value give by users for URL Field.
System ask Facebook, Twitter, Google+ & etc
Can anyone suggest us with best way.
We are using the following pattern,
/((?:https?\:\/\/www\.)|(?:[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$))/i
Thanks,
You can start with using input type as url
example
<form name="form1" ng-controller="x">
<label>Enter Site Name:</label>
<input type="url" ng-model="initialwebsite" name="name" required />
<span style="color:red" ng-show="form1.name.$error.required">
You Can't Leave This Field Empty</span>
<span style="color:red" ng-show="form1.name.$error.url">
Sorry Not a Valid URL, Don't Forget to Use http://</span>
<input type="submit" value="Submit"/>
</form>
For further validation you can refer this link
As example, you can try this one
"#([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\x00A0-\xD7FF\xF900-\xFDCF\xFDF0-\xFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*#)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\x00A0-\xD7FF\xF900-\xFDCF\xFDF0-\xFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\x00A0-\xD7FF\xF900-\xFDCF\xFDF0-\xFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|#)*)*|(\/((([a-z]|\d|-|\.|_|~|[\x00A0-\xD7FF\xF900-\xFDCF\xFDF0-\xFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|#)+(\/(([a-z]|\d|-|\.|_|~|[\x00A0-\xD7FF\xF900-\xFDCF\xFDF0-\xFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|#)*)*)?)|((([a-z]|\d|-|\.|_|~|[\x00A0-\xD7FF\xF900-\xFDCF\xFDF0-\xFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|#)+(\/(([a-z]|\d|-|\.|_|~|[\x00A0-\xD7FF\xF900-\xFDCF\xFDF0-\xFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|#)*)*)|((([a-z]|\d|-|\.|_|~|[\x00A0-\xD7FF\xF900-\xFDCF\xFDF0-\xFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|#)){0})(\?((([a-z]|\d|-|\.|_|~|[\x00A0-\xD7FF\xF900-\xFDCF\xFDF0-\xFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|#)|[\xE000-\xF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\x00A0-\xD7FF\xF900-\xFDCF\xFDF0-\xFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|#)|\/|\?)*)?#iS"

Using a form to upload a file to the Google App Engine using a static URL

I am using CrashRpt C++ to upload crash reports from a piece of software I wrote. Crashrpt uploads the data from the crash report to a URL that is set when the program load, in the same way a browser would using a web form.
The CrashRpt send data like this HTML
<html>
<form action="THE_WEBSITE" method="POST" enctype="multipart/form-data">
Application name:<input type="text" name="appname">
Application version:<input type="text" name="appversion">
Email from:<input type="text" name="emailfrom">
Email subject:<input type="text" name="emailsubject">
Crash GUID:<input type="text" name="crashguid">
MD5:<input type="text" name="md5">
Attach ZIP file:<input type="file" name="crashrpt">
<input type="submit" name="Submit">
</form>
</html>
The only web service we have is the Google App Engine. Is there any way we can actually upload a file using a form to a static address and not the blobstore that requires a dynamic one.
I assume NO.
Here's a trivial, self-contained example of how to upload (small -- less than 1 MB!) files to a static url with GAE (with this example, use text files only, since that's how I display them):
import webapp2
from google.appengine.api import users
from google.appengine.ext import ndb
class UserFile(ndb.Model):
filename = ndb.StringProperty()
filedata = ndb.BlobProperty()
class UploadFormHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write('<html><body>')
self.response.out.write('<form action="/upload_file" method="POST" enctype="multipart/form-data">')
self.response.out.write(
'''Upload File: <input type="file" name="file"><br>
<input type="submit" name="submit" value="Submit">
</form></body></html>''')
class UploadHandler(webapp2.RequestHandler):
def post(self):
thefile = self.request.POST.get('file')
filename = thefile.filename
userfile = UserFile(
id=filename, filename=filename,
filedata=thefile.value)
userfile.put()
self.redirect('/view_file/%s' % filename)
class ViewHandler(webapp2.RequestHandler):
def get(self, fileid):
k = ndb.Key(UserFile, fileid)
userfile = k.get()
self.response.headers['Content-Type'] = 'text/plain'
self.response.write(userfile.filedata)
app = webapp2.WSGIApplication([('/', UploadFormHandler),
('/upload_file', UploadHandler),
('/view_file/([^/]+)?', ViewHandler),
], debug=True)

Angularjs Open Window With Post Params

I have a two forms in my application.
In the first one the user sets his data. When submitted the form data gets checked and an entry is made into a database with $http.
The second one is hidden and contains the payment parameters for either paypal or amazon payments.
I need one of two solutions (I can do A but my gut feeling is that B is better):
A)
Trigger the submit function of form B when the promise of form A's http is resolved.
This would be one solution which is not very good I guess:
HTML
<form method="POST" action="{{spendenController.paypal.actionUrl}}" target="_top" id="paypalForm">
<input type="hidden" name="cmd" value="_donations">
<input type="hidden" name="business" value="{{spendenController.paypal.accountEmail}}">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="lc" value="DE">
<input type="hidden" name="amount" value="{{spendenController.spenden.amount}}">
<input type="hidden" name="item_name" value="Spende">
<input type="hidden" name="notify_url" value="{{spendenController.paypal.notifyUrl}}">
<input type="hidden" name="return" value="{{spendenController.paypal.successRedirectUrl}}" />
<input type="image" src="https://www.paypalobjects.com/de_DE/DE/i/btn/btn_donateCC_LG.gif" border="0" name="btnSubmit" alt="Jetzt einfach, schnell und sicher online bezahlen – mit PayPal.">
<img alt="" border="0" src="https://www.paypalobjects.com/de_DE/i/scr/pixel.gif" width="1" height="1">
</form>
Controller
document.getElementById('paypalForm').submit()
B)
Or load a page with POST params directly from the controller/a service when the promise is resolved. In that case I wouldn't even need the second form.
Question: How to open a page with POST from the controller?
I do not just want to send POST data with $http.post I need the user to see the paypal checkout window in order to fulfill the payment.

roundcubelogin with window.open function

I have already done autologin to roundcube via the following script
<form name="webmail" action="http://localhost/roundcube_mail/" method="post">
<div class="info" style="color:#f00;display:none"></div>
<input name="_action" id="_action"value="login" type="hidden" />
<input name="_timezone" id="_timezone" value="_default_" type="hidden" />
<input name="ajax" id="ajax" value="1" type="hidden" />
User <input name="_user" id="_user" type="text" value="anupam#excoflare.com"/><br>
Pass <input name="_pass" id="_pass"type="password" value="anupam123"/><br>
<input type="submit" >
</form>
it will work correctly.But i want to auto login roundcubemail via java script with window.open method for my p
The problem is that you want do do a POST request instead of a GET request. This might help you:
JavaScript post request like a form submit

Resources