Coder Social home page Coder Social logo

ahmedfgad / androidflask Goto Github PK

View Code? Open in Web Editor NEW
53.0 53.0 30.0 7.85 MB

Image Upload from Android to Python-Based Flask Server

Home Page: https://www.linkedin.com/in/ahmedfgad

License: MIT License

Java 82.96% Python 17.04%
anaconda anaconda3 android android-application android-studio client-server client-side flask java python server server-side upload upload-file upload-images upload-pictures xml

androidflask's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

androidflask's Issues

License?

Hi, and thanks for your cool project! Did you already decide what license to put it under (like, Apache, MIT, GPL…)?

Different image paths

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!

Unable to connect to server

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?

KeyError: 'image'

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'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.