Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 44
Registered: ‎01-07-2013
My Device: 9300
My Carrier: blackberry

Image Uploading to Server

Hi all,

               i need to upload the image to the server i have used file picker to fetch the image, i have attached my  sample code but its not working

 

my file picker code

                     Button {
                        text: "Change Profile Image"
                        onClicked {
                             filePicker.open();
                        }                   
                           attachedObjects: [
                            FilePicker {
                                id: filePicker
                                property string selectedFile
                                type: FileType.Picture
                                onFileSelected: {
                                    selectedFile = selectedFiles[0]
                                    image.imageSource = selectedFile
                                       _settings.showToast( selectedFile);
                                      _settings.isUpdate(selectedFile);
                                }
                            }
                       ]
                                                               
                    

 my image update code in c++

 

 

void Settings::isUpdate(QString selectedFile){
	   QString path("asset:///Icon/mess.jpg");
   	    QNetworkRequest requete(QUrl("http://IP.IP.IP:2242/api?type=uploadimages&name=IMG_00000001.jpg&pin=123456")); 
	    QByteArray boundary"-------------------------87142694621188";
	    QFile file(path);
	    if (!file.open(QIODevice::ReadOnly))
	    {
	       return;
	    }
	    QByteArray fileContent(file.readAll());
	    QByteArray data = "--" + boundary + "\r\n";
	    data += "Content-Disposition: form-data; name=\"data\"; filename=\"IMG_00000001.jpg\";\r\n";
 	    data += "Content-Type: image/jpg\r\n\r\n" + fileContent + "\r\n";
	    data += "--" + boundary + "--\r\n";
	    requete.setRawHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
	    requete.setRawHeader("Content-Length",QString::number(data.size()).toAscii()); 
	    file.close();
	    qDebug() <<"data"<< data.size();
	    QNetworkAccessManager *am = new QNetworkAccessManager(this);
	    QNetworkReply *reply = am->post(requete,"&data="+data);
	    QObject::connect(am, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
}
void Settings::replyFinished(QNetworkReply *reply)
{
    reply->open(QIODevice::ReadOnly);
     if(reply->error() == QNetworkReply::NoError)
    {
        QByteArray str=(reply->readAll());
        QString response = QString::fromUtf8(str.data(), str.size());
        showToast(response);
        qDebug()<<" re "<<response;
    }
    else
        qDebug()<<"error response server";
}

Can anyone help me to solve this issue

 thanks

Developer
Posts: 589
Registered: ‎10-17-2010
My Device: (BlackBerry Z10)-> Q10/Passport Dual Use

Re: Image Uploading to Server

BUMP

 

Contributor
Posts: 44
Registered: ‎01-07-2013
My Device: 9300
My Carrier: blackberry

Re: Image Uploading to Server

Hi,

     I need to do onClick in a listview, i have used listview in qml my sample code 

ListView {
    verticalAlignment: VerticalAlignment.Center
    horizontalAlignment: HorizontalAlignment.Center
    layout: FlowListLayout {
    }
    dataModel: mydatamodel
    listItemComponents: [
        ListItemComponent {
            type: "item"
            Container {
                layout: DockLayout {
                }

                Button {
                    id: samplebutton
                    text: "Button"
                    horizontalAlignment: HorizontalAlignment.Right
                    onClicked: {
                        //click event not fired here..
                         
                    }
                }
                Label {
                    horizontalAlignment: HorizontalAlignment.Left
                    text: "Sample Label"
                }
                Divider {
                    horizontalAlignment: HorizontalAlignment.Fill
                }
            }
        }
    ]
    onTriggered: {
        var selectedItem = dataModel.data(indexPath);
    }
}

 Any solution ,Thanks

Developer
Posts: 589
Registered: ‎10-17-2010
My Device: (BlackBerry Z10)-> Q10/Passport Dual Use

Re: Image Uploading to Server

What is the status of your upload script? If it is working, please share the code with the community.

Developer
Posts: 313
Registered: ‎05-31-2010
My Device: Alpha 10, Bold 9900, Storm 9530, Tour 9630, Curve 9320, Curve 8900
My Carrier: All

Re: Image Uploading to Server

[ Edited ]

Have you verify the function of uploading file which you programmed is working properly or not?

 

I think that the boundary string should be put at both the front and end of filecontent. But your code seems like the boundary is only at the end of filecontent. 

 

Can you make a simple test for this uploading function "isUpdate()" at first? 

 




p(^_^)q
Good good study, day day up