Markdown Monster
MetaWeblogApi uploads images again of existing post
Gravatar is a globally recognized avatar based on your email address. MetaWeblogApi uploads images again of existing post
  darkthread
  All
  Sep 22, 2018 @ 08:48pm

Hi, I am using Markdown Monster to publish blog post via MetaWeblogApi. It works fine for new post with images (from local folder), the images were uploaded successfully. But when I modified the post and published it again, the images were uploaded again. I expect that the img src "/localFolder/filename" will be changed to "http://blog-server/serverFolder/filename" after post published to prevent from duplicated uploading, but it doesn't happen. Is this not implemented or a issue?

Gravatar is a globally recognized avatar based on your email address. re: MetaWeblogApi uploads images again of existing post
  Rick Strahl
  darkthread
  Sep 24, 2018 @ 02:34am

That's actually the way this is supposed to work. I don't think MM should change your document to reflect the new URLs - that would break the whole edit flow if you make changes to an image and re-upload.

The server has to be able to deal with uploaded images even on edits. The server gets a post id and the image name, and based on that the server should be able to determine that the image already exists and overwrites the image or determines if it's the same and just ignores it (based on size perhaps).

What's the application hosting your Metaweblog API backend that you're sending the posts to? I suspect it's specific to the way that backend is dealing with incoming images.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: MetaWeblogApi uploads images again of existing post
  darkthread
  Rick Strahl
  Sep 24, 2018 @ 07:20am

Thanks for clarifying.
I am using Miniblog.Core and Windows Live Writer and Open Live Writer works fine with it. They never upload duplicated images with the identitical MetaWeblogApi implemnentation.
But you are right, Live Writer didn't overwrite the document, either. After digging deeper, I found that it stores the mapping data XML inside its .wpost file format. That's why it can prevent from duplicated uploading from client side. Indeed, changing the original document doesn't seem a good idea, how about storing the uploaded image mapping in YAML metadata store? I think I will give it a try.

Gravatar is a globally recognized avatar based on your email address. re: MetaWeblogApi uploads images again of existing post
  darkthread
  darkthread
  Sep 24, 2018 @ 09:35am

A mapping dictionary of filename with content hash to MediaObjectInfo is stored in YAML. When calling PublishCompletePost(), if filename and image binary matches any key in the dictoinary, SendImages() will retrieve the url from dictionary instead of calling NewMediaObject(). If the filename or image is modified, the new image file will be uploaded.

Here's a sample of YAML containing with uploaded MediaObjectInfo, is it acceptable?

---
title: test 12345
weblogName: My Blog
postId: 636734015982601822
postDate: 2018-09-24T23:59:45.7430473+08:00
mediaObjects:
  dough-2948026_1280.jpg#JTT8SBZxq+MWExjkIJJgbg==:
    uRL: http://blog.sample.net/Posts/files/dough-2948026_1280_636734029171107682.jpg
  street-marathon-1149220_1280.jpg#nGZx/FZ4qWva2JwBqVXabA==:
    uRL: http://blog.sample.net/Posts/files/street-marathon-1149220_1280_636734029171555814.jpg
---
![](dough-2948026_1280.jpg)![](street-marathon-1149220_1280.jpg)
````
Gravatar is a globally recognized avatar based on your email address. re: MetaWeblogApi uploads images again of existing post
  Rick Strahl
  darkthread
  Sep 24, 2018 @ 01:26pm

So giving this some more thought - I think the way to do this might be to replace the links as an option. You mention Live Writer and I do seem to remember that it would pick up the downloaded image URL and embed it into the post effectively changing the post with the new link.

I still think that's not the behavior one would want but if the blog engine doesn't support idempotent uploads of the same file, then that option is probably the cleanest approach. With Live Writer the problem always was that it would create new image filenames each and every time it would upload so if you uploaded the same image with an update it would pollute the server with images that would never be used. This is the primary reason why I much prefer to have images uploaded each time you repost and let the server assign the image ids in a consistent way so an updated image updates an already existing image without the waste.

+++ Rick ---

© 1996-2024