WordPress.org

Ready to get started?Download WordPress

Forums

Error "Could not write file wpid-m (Invalid file type) (9 posts)

  1. Cocoanut
    Member
    Posted 5 years ago #

    Hi,

    I'm trying to write some AppleScript to upload images that I have resized. I do this so the images register in the Media Manager rather than FTP where it doesn't.

    I am receiving this error message but I don't understand why I am receiving it.

    " xmlrpc.php got an error: Could not write file wpid-m (Invalid file type) (525768928)"

    Any suggestions would be appreciated. I have included the code here in case there are any AppleScript folk out there who may have done this before. Have actually implemented an Automator workflow with AppleScript actions inside.

    1. Get Specified Finder Items (point to specific file)

    2. Run AppleScript:

    on run {input, parameters}
    	set thePath to quoted form of POSIX path of input
    	set theScript to "openssl base64 < " & thePath
    	return do shell script theScript
    end run

    3. Run AppleScript:

    on run {input, parameters}
    
    	set myUsername to "myusername"
    	set myPassword to "mypassword"
    
    	set theFileName to "imagename.jpg"
    
    	set theFilePath to "Mac HD:Users:myusername:Desktop:imagename.jpg"
    
    	tell application "Image Events"
    		launch
    		set this_image to open theFilePath
    		set theType to file type of this_image
    		close this_image
    	end tell
    
    	set fileType to theType
    	set overwrite to true
    	display dialog theFileName & " " & fileType & " " & overwrite & " base64=" & input
    	tell application "http://mywordpresssite.com/xmlrpc.php"
    		set returnValue to call xmlrpc {method name:"wp.uploadFile", parameters:{1, myUsername, myPassword, theFileName, fileType, input, overwrite}}
    	end tell
    	return returnValue
    end run

    The parameters end up being as follows:

    theFilename = "imagename.jpg"
    fileType = "JPEG"
    input = base64 encoded image
    overwrite = true

  2. Joseph Scott
    Member
    Posted 5 years ago #

    Are you able to upload files normally via wp-admin? If WP is unable to write to the file then this might be a server setup problem.

    The wp.uploadFile XML-RPC method takes arguments that look like:

    blog_id
    username
    password
    file_data (struct)
        name (filename)
        bits (base64 data)
        type (mime type for bits)
        overwrite (boolean)
  3. Cocoanut
    Member
    Posted 5 years ago #

    Hi Joseph,

    Yes, I am able to upload normally via wp-admin

    I'm not sure if I'm forming the parameters correctly. Is there something I need to specifically pass along that denotes a file_data struct? Do I have the fileType correct or should I be passing "image/jpeg" instead of "JPEG" ? I have tried both in anyway and I receive the same error message.

  4. Cocoanut
    Member
    Posted 5 years ago #

    I have mode some progress on this issue. By Joseph providing the arguments list, it prompted me to reconsider the way I was passing the file_data parameters. I changed the code to form a structure in AppleScript.

    on run {input, parameters}
    	set myUsername to "myusername"
    	set myPassword to "mypassword"
    	set parameterStruct to {|name|:"imagename.jpg", type:"image/jpeg", bits:input, overwrite:true}
    
    	tell application "http://twih.kamboville.com/xmlrpc.php"
    		set returnValue to call xmlrpc {method name:"wp.uploadFile", parameters:{1, myUsername, myPassword, parameterStruct}}
    	end tell
    	return returnValue
    end run

    The code runs successfully, something is uploaded. Unfortunately, the file name uploaded is prepended with "wpid-". So the file name is now "wpid-imagename.jpg" and there is a question mark in place of the actual image.

    The returnValue is

    {|file|:"wpid-imagename.jpg", |url|:"http://mywordpresssite.com/wp-content/uploads/wpid-imagename.jpg", type:"image/jpeg"}

    Which is very strange considering the filename I'm passing is "imagename.jpg".

    I used a packet sniffer to capture the XML file being sent to the server. Not sure if this is what it should be.

    <?xml version="1.0" encoding="UTF-8"?>
      <methodCall>
        <methodName>wp.uploadFile</methodName>
        <params>
          <param>
              <value>
                <i4>1</i4>
              </value>
          </param>
          <param>
              <value>
                <string>myusername</string>
              </value>
          </param>
          <param>
              <value>
                <string>mypassword</string>
              </value>
          </param>
          <param>
              <value>
                <struct>
                  <member>
                    <name>name</name>
                      <value>
                        <string>imagename.jpg</string>
                      </value>
                  </member>
                  <member>
                    <name>type</name>
                      <value>
                        <string>image/jpeg</string>
                      </value>
                  </member>
                  <member>
                    <name>bits</name>
                      <value>
                        <array>
                          <data>
                            <value>                   <string>/9j/4AAQSkZJRgABAAEAYABgAAD//gAfTEVBRCBUZWNobm9sb2dpZXMgSW5jLiBWMS4wMQD/2wCEAAgFBgcGBQgHBgcJCAgJDBQNDAsLDBgREg4UHRkeHhwZHBsgJC4nICIrIhscKDYoKy8xMzQzHyY4PDgyPC4yMzEBCAkJDAoMFw0NFzEhHCExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMf/EAaIAAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKCwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoLEAA
    
    @@ LOTS MORE FUNNY CHARACTERS HERE @@
    
    lXJXbWqOaauyfUVENs7xkqwOM1EK89NSIwXNYyG1C7B2idsHPp6V3JnSqULbEbzzyrLumcFY2cEYzkLms6s5Ri2i6dKHMlYyNQvroWmnt57Zlg3vwOTuI9K8N47ERtaR6ccNSi3aJPFI82js0rbmWcAE9cbaSr1Kq993IlCMNYohT09KRmzWtLuVbGNGPmKZCu1+RjFa9GZS3HXthAFV0BQnqAeKqyauTKbjsf/9k=</string>
                            </value>
                          </data>
                        </array>
                      </value>
                  </member>
                  <member>
                    <name>overwrite</name>
                      <value>
                        <boolean>1</boolean>
                      </value>
                  </member>
                </struct>
              </value>
          </param>
        </params>
      </methodCall>
  5. Joseph Scott
    Member
    Posted 5 years ago #

    The file data is base64 encoded, but it's marked in the XML as a string:

    <string>/9j/4AAQSkZJRgABAAEAYABgAAD//gAfTEVBRCBUZWNobm9sb2dpZXMgSW5jLiBWMS4wMQD/2wCEAAgFBgcGBQgHBgcJCAgJDBQNDAsLDBgREg4UHRkeHhwZHBsgJC4nICIrIhscKDYoKy8xMzQzHyY4PDgyPC4yMzEBCAkJDAoMFw0NFzEhHCExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMf/EAaIAAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKCwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoLEAA
    
    @@ LOTS MORE FUNNY CHARACTERS HERE @@
    
    lXJXbWqOaauyfUVENs7xkqwOM1EK89NSIwXNYyG1C7B2idsHPp6V3JnSqULbEbzzyrLumcFY2cEYzkLms6s5Ri2i6dKHMlYyNQvroWmnt57Zlg3vwOTuI9K8N47ERtaR6ccNSi3aJPFI82js0rbmWcAE9cbaSr1Kq993IlCMNYohT09KRmzWtLuVbGNGPmKZCu1+RjFa9GZS3HXthAFV0BQnqAeKqyauTKbjsf/9k=</string>

    should be:

    <base64>/9j/4AAQSkZJRgABAAEAYABgAAD//gAfTEVBRCBUZWNobm9sb2dpZXMgSW5jLiBWMS4wMQD/2wCEAAgFBgcGBQgHBgcJCAgJDBQNDAsLDBgREg4UHRkeHhwZHBsgJC4nICIrIhscKDYoKy8xMzQzHyY4PDgyPC4yMzEBCAkJDAoMFw0NFzEhHCExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMf/EAaIAAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKCwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoLEAA
    
    @@ LOTS MORE FUNNY CHARACTERS HERE @@
    
    lXJXbWqOaauyfUVENs7xkqwOM1EK89NSIwXNYyG1C7B2idsHPp6V3JnSqULbEbzzyrLumcFY2cEYzkLms6s5Ri2i6dKHMlYyNQvroWmnt57Zlg3vwOTuI9K8N47ERtaR6ccNSi3aJPFI82js0rbmWcAE9cbaSr1Kq993IlCMNYohT09KRmzWtLuVbGNGPmKZCu1+RjFa9GZS3HXthAFV0BQnqAeKqyauTKbjsf/9k=</base64>
  6. Cocoanut
    Member
    Posted 5 years ago #

    Ahh. Thats what it is.

    Hmm... I have no idea how to change that through AppleScript.

    Thank you for your assistance, Joseph.

    I'll hit the AppleScript forum and see if there is a solution there.

  7. kisso
    Member
    Posted 5 years ago #

    actually i have a question on wp.uploadFile.

    what is struct data, what should be that data, also base64 does that mean that i have to convert the image to base64 first and then put it as a parameter?

    if someone could help me
    thanks a lot in advance

  8. Joseph Scott
    Member
    Posted 5 years ago #

    There are some examples of the different data types at http://en.wikipedia.org/wiki/Xml-rpc

    Yes, for base64 fields the contents must be base64 encoded.

  9. kisso
    Member
    Posted 5 years ago #

    i have a problem with the code. it appears i have something wrong can someone tell me if this code is right:

    ` params.addElement("6979452");
    params.addElement(usename);
    params.addElement(password);

    final Hashtable media = new Hashtable(0);

    media.put("name", "images.jpg");
    media.put("type","image/jpeg" ); //file.getMIMEType()
    media.put("bits", "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5Ojf/2wBDAQoKCg0MDRoPDxo3JR8lNzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzf/wAARCAAwADADASIAAhEBAxEB/8QAGgAAAgMBAQAAAAAAAAAAAAAAAwcEBQYIAf/EAC0QAAIBAgUDAgYCAwAAAAAAAAECAwQRAAUSITEGE1FBYQcUIiNxkTJCJGKB/8QAGQEBAAMBAQAAAAAAAAAAAAAAAwIFBgEE/8QAKREAAQIFAgUEAwAAAAAAAAAAAQACAwQREiFBsQUTUWHBFCIxcZHh8P/aAAwDAQACEQMRAD8AeGBQ1EU5kEMschjcpJocHQw5U24O42xmesKqPMIpcghqnpK+VVemk7mlJJFIbt6gbgkW2NuQRfCkzKvz/KOoY6qu71PmcDq/3du7pGkHbZrgaSRz+8G6JaVZyvDfUQy4uodB5+tl0KDj3CV6L6zmFTQrPNUTz1Waf5CMxLMjx6EFzyFdmNv9Rhm1XV/T9JKYps0pzKJeyUjJdg+2xCg2554vtjoeCKoI0jFhvDWi6vQK9OAq/dYlf4Da/k4CWarcqhK06mxccufA9vfEtVCqFUAAbAAYjl57b/peJYrr/p3p/MIfnMzrIssqiLCp2vJb0Zf729tx5thTZtPFSI1I2cPmWWFQBrV0QPcGwV9wdI5FvH5uvivldTRdQS1T16MtWe5HGzEuq8Hkmyg7Dj2Fhhe1QPbDEtIqkM3c3B8Daxtv6EYJzhfQhayVhGHKB7Xl2KioFBucfhTqYRxP87ltVaqD64hHILKFJGphyNxtfzzvi86HiyuTN6StzuvOX01MyssYR2aVgRpGoAhVuNyfwLcjG0DyQzpUxSKCoCESAALcEst77D3Fjb8EYs5gYcyMUZNiuloyxABABHrck3F24JP6m4DRHBfz2G72n4x31zXvuupKGspq6mSeiningYfTJEwZT+sSMKP4O57BT1M2Sy08cUs15FlLFWdhwpDHfY7afB2O5w3AbjCsdcKqhnJYy0Us00Wb616Vp+paELJqNTBHIKb7pRA7AWLWBuAQMJpeguoBXSQ1lEaaKBe5JUSH7EaAXLlxs1h6C5x0TiNmVDDmVBPRVIYwzxmNwrEGx53GIvhh2U8pxKLLtsGRt/dOq5dWmf5kLSlpHeTTGe39bA7AADgEf135wSlgjZJL27e8agG4UDx7E8/83OHrQ/DzKsuu1K0jS/NxzK0rX0IrX0Ajfgnfm9ieMQ5vhflc+a1dU1XURQTtrSCEBe2xN23NwVO+1tr/AIwXKfRXLOKyTYhdQ084VH0V0FmVFndFW5gbU0KLPG4Kk6rfxKkGx8+nqrAgYbK8DAaKkhoaSGkpVKQQoEjUsW0qOBcknB8O1toWempl8w+52mAv/9k=" );
    media.put("overwrite", "true");

    params.addElement(media);

    System.out.println("before execute");
    Object response = conn.execute("wp.uploadFile", params);
    Hashtable result = (Hashtable)response;

    return ((String) result.get("url"));`

Topic Closed

This topic has been closed to new replies.

About this Topic