powered by Jive Software

Smack FileUploadManager Not Uploading Images



When i am using FileUploadManager It Upload The File In Old Server But Not Uploading In New Server Using Smack FileUploadManager Why?


You’re gonna have to give some more details if you expect helpful feedback :smile:.
What is the “Old Server”, what the “New Server”? What do the logs say? Have you looked into the stanzas that are sent back and forth?


In New Server It Is MangooseIm And When I Use FileUploadManager Than It Say 403 Forbidden While Uploading Media File To Server In Chat.


Do You Have Method For It? I Have TeamWeaver So Can You Help Me In TeamWeaver?


I Have Problem In This Function.
private void uploadFile(final File file, final Slot slot, UploadProgressListener listener) throws IOException {
final long fileSize = file.length();
// TODO Remove once Smack’s minimum Android API level is 19 or higher. See also comment below.
if (fileSize >= Integer.MAX_VALUE) {
throw new IllegalArgumentException("File size " + fileSize + " must be less than " + Integer.MAX_VALUE);
final int fileSizeInt = (int) fileSize;

    // Construct the FileInputStream first to make sure we can actually read the file.
    final FileInputStream fis = new FileInputStream(file);

    final URL putUrl = slot.getPutUrl();

    final HttpURLConnection urlConnection = (HttpURLConnection) putUrl.openConnection();

    // TODO Change to using fileSize once Smack's minimum Android API level is 19 or higher.
    urlConnection.setRequestProperty("Content-Type", "application/octet-stream;");
    for (Entry<String, String> header : slot.getHeaders().entrySet()) {
        urlConnection.setRequestProperty(header.getKey(), header.getValue());

    final SSLSocketFactory tlsSocketFactory = this.tlsSocketFactory;
    if (tlsSocketFactory != null && urlConnection instanceof HttpsURLConnection) {
        HttpsURLConnection httpsUrlConnection = (HttpsURLConnection) urlConnection;

    try {
        OutputStream outputStream = urlConnection.getOutputStream();

        long bytesSend = 0;

        if (listener != null) {
            listener.onUploadProgress(0, fileSize);

        BufferedInputStream inputStream = new BufferedInputStream(fis);

        // TODO Factor in extra static method (and re-use e.g. in bytestream code).
        byte[] buffer = new byte[4096];
        int bytesRead;
        try {
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
                bytesSend += bytesRead;

                if (listener != null) {
                    listener.onUploadProgress(bytesSend, fileSize);
        finally {
            try {
            catch (IOException e) {
                LOGGER.log(Level.WARNING, "Exception while closing input stream", e);
            try {
            catch (IOException e) {
                LOGGER.log(Level.WARNING, "Exception while closing output stream", e);

        int status = urlConnection.getResponseCode();
        switch (status) {
        case HttpURLConnection.HTTP_OK:
        case HttpURLConnection.HTTP_CREATED:
        case HttpURLConnection.HTTP_NO_CONTENT:
            throw new IOException("Error response " + status + " from server during file upload: "
                            + urlConnection.getResponseMessage() + ", file size: " + fileSize + ", put URL: "
                            + putUrl);
    finally {


Sounds like you misconfigured your server.

Please provide a stacktrace that shows the exception, as well as a stanza trace, the source code of smack is not useful :smile:.