ahmedfgad / androidflask Goto Github PK
View Code? Open in Web Editor NEWImage Upload from Android to Python-Based Flask Server
Home Page: https://www.linkedin.com/in/ahmedfgad
License: MIT License
Image Upload from Android to Python-Based Flask Server
Home Page: https://www.linkedin.com/in/ahmedfgad
License: MIT License
Hi, currently this error shows no matter what type of image file seems to be selected. Any advice please? Thank you
Hi, and thanks for your cool project! Did you already decide what license to put it under (like, Apache, MIT, GPL…)?
Hi, anyway to make your app work with the path to an newly created folder other than the standard Android Gallery? Eg:
File storageDir = getExternalFilesDir(Environment.DIRECTORY_DCIM);
When I try to add an image from my newly created folder DCIM (in Internal Storage - Android- data-...) I get the 'Something went wrong' toast.
Thanks!
Hi,
I have implemented this project in Kotlin:
`class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
fun connectServer(v: View?) {
val ipv4AddressView = findViewById<EditText>(R.id.IPAddress)
val ipv4Address = ipv4AddressView.text.toString()
val portNumberView = findViewById<EditText>(R.id.portNumber)
val portNumber = portNumberView.text.toString()
val postUrl = "http://$ipv4Address:$portNumber/"
val postBodyText = "Hello"
val mediaType: MediaType? = "text/plain; charset=utf-8".toMediaTypeOrNull()
val postBody = RequestBody.create(mediaType, postBodyText)
postRequest(postUrl, postBody)
}
fun postRequest(postUrl: String, postBody: RequestBody) {
val client = OkHttpClient()
val request: Request = Request.Builder()
.url(postUrl)
.post(postBody)
.build()
client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
// Cancel the post on failure.
call.cancel()
// In order to access the TextView inside the UI thread, the code is executed inside runOnUiThread()
runOnUiThread {
val responseText = findViewById<TextView>(R.id.responseText)
responseText.text = "Failed to Connect to Server"
}
}
@Throws(IOException::class)
override fun onResponse(call: Call, response: Response) {
// In order to access the TextView inside the UI thread, the code is executed inside runOnUiThread()
runOnUiThread {
val responseText = findViewById<TextView>(R.id.responseText)
try {
responseText.text = response.body!!.string()
} catch (e: IOException) {
e.printStackTrace()
}
}
}
})
}
}`
The python server is up and running :
Can you help with this by any chance?
Hi, if I want to execute a shell script command (ex. subprocess.run(['./test.sh'])) after the return statement, what should I do?
While uploading the image from mobile im getting this error. I even tried using 4.9.0 version of okhttp but still the same error.
192.168.31.250 - - [07/Dec/2020 16:08:55] "POST / HTTP/1.1" 500 -
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 2464, in call
return self.wsgi_app(environ, start_response)
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functionsrule.endpoint
File "/home/ubuntu/Downloads/AndroidFlask-master/Part 2/FlaskServer/flask_server.py", line 11, in handle_request
imagefile = flask.request.files['image']
File "/home/ubuntu/.local/lib/python3.6/site-packages/werkzeug/datastructures.py", line 442, in getitem
raise exceptions.BadRequestKeyError(key)
werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
KeyError: 'image'
File "/home/raghavz/.local/lib/python3.6/site-packages/werkzeug/datastructures.py", line 442, in getitem
raise exceptions.BadRequestKeyError(key)
werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
KeyError: 'image'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.